@@ -927,15 +927,26 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
927927 final Long accountId = cmd .getAccountId ();
928928 final Long domainId = cmd .getDomainId ();
929929 final Long imageStoreId = cmd .getImageStoreId ();
930+ ConfigKey <?> configKey = null ;
930931 Optional optionalValue ;
931- final ConfigKey <?> configKey = _configDepot .get (name );
932- if (configKey == null ) {
933- s_logger .warn ("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface" );
934- throw new InvalidParameterValueException ("Config parameter with name " + name + " doesn't exist" );
932+ String defaultValue ;
933+ String category ;
934+ String configScope ;
935+ final ConfigurationVO config = _configDao .findByName (name );
936+ if (config == null ) {
937+ configKey = _configDepot .get (name );
938+ if (configKey == null ) {
939+ s_logger .warn ("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface" );
940+ throw new InvalidParameterValueException ("Config parameter with name " + name + " doesn't exist" );
941+ }
942+ defaultValue = configKey .defaultValue ();
943+ category = configKey .category ();
944+ configScope = configKey .scope ().toString ();
945+ } else {
946+ defaultValue = config .getDefaultValue ();
947+ category = config .getCategory ();
948+ configScope = config .getScope ();
935949 }
936- String defaultValue = configKey .defaultValue ();
937- String category = configKey .category ();
938- String configScope = configKey .scope ().toString ();
939950
940951 String scope = "" ;
941952 Map <String , Long > scopeMap = new LinkedHashMap <>();
@@ -971,7 +982,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
971982 throw new InvalidParameterValueException ("unable to find zone by id " + id );
972983 }
973984 _dcDetailsDao .removeDetail (id , name );
974- optionalValue = Optional .ofNullable (configKey .valueIn (id ));
985+ optionalValue = Optional .ofNullable (configKey != null ? configKey .valueIn (id ): config . getValue ( ));
975986 newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
976987 break ;
977988
@@ -981,13 +992,13 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
981992 throw new InvalidParameterValueException ("unable to find cluster by id " + id );
982993 }
983994 ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao .findDetail (id , name );
984- newValue = configKey .value ().toString ();
995+ newValue = configKey != null ? configKey .value ().toString () : config . getValue ();
985996 if (name .equalsIgnoreCase ("cpu.overprovisioning.factor" ) || name .equalsIgnoreCase ("mem.overprovisioning.factor" )) {
986997 _clusterDetailsDao .persist (id , name , newValue );
987998 } else if (clusterDetailsVO != null ) {
988999 _clusterDetailsDao .remove (clusterDetailsVO .getId ());
9891000 }
990- optionalValue = Optional .ofNullable (configKey .valueIn (id ));
1001+ optionalValue = Optional .ofNullable (configKey != null ? configKey .valueIn (id ): config . getValue ( ));
9911002 newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
9921003 break ;
9931004
@@ -997,7 +1008,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
9971008 throw new InvalidParameterValueException ("unable to find storage pool by id " + id );
9981009 }
9991010 _storagePoolDetailsDao .removeDetail (id , name );
1000- optionalValue = Optional .ofNullable (configKey .valueIn (id ));
1011+ optionalValue = Optional .ofNullable (configKey != null ? configKey .valueIn (id ) : config . getValue ( ));
10011012 newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
10021013 break ;
10031014
@@ -1010,7 +1021,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
10101021 if (domainDetailVO != null ) {
10111022 _domainDetailsDao .remove (domainDetailVO .getId ());
10121023 }
1013- optionalValue = Optional .ofNullable (configKey .valueIn (id ));
1024+ optionalValue = Optional .ofNullable (configKey != null ? configKey .valueIn (id ) : config . getValue ( ));
10141025 newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
10151026 break ;
10161027
@@ -1023,7 +1034,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
10231034 if (accountDetailVO != null ) {
10241035 _accountDetailsDao .remove (accountDetailVO .getId ());
10251036 }
1026- optionalValue = Optional .ofNullable (configKey .valueIn (id ));
1037+ optionalValue = Optional .ofNullable (configKey != null ? configKey .valueIn (id ) : config . getValue ( ));
10271038 newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
10281039 break ;
10291040
@@ -1036,7 +1047,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
10361047 if (imageStoreDetailVO != null ) {
10371048 _imageStoreDetailsDao .remove (imageStoreDetailVO .getId ());
10381049 }
1039- optionalValue = Optional .ofNullable (configKey .valueIn (id ));
1050+ optionalValue = Optional .ofNullable (configKey != null ? configKey .valueIn (id ) : config . getValue ( ));
10401051 newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
10411052 break ;
10421053
@@ -1045,7 +1056,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
10451056 s_logger .error ("Failed to reset configuration option, name: " + name + ", defaultValue:" + defaultValue );
10461057 throw new CloudRuntimeException ("Failed to reset configuration value. Please contact Cloud Support." );
10471058 }
1048- optionalValue = Optional .ofNullable (configKey .value ());
1059+ optionalValue = Optional .ofNullable (configKey != null ? configKey .value () : config . getValue ());
10491060 newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
10501061 }
10511062
0 commit comments