@@ -914,15 +914,26 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
914914 final Long accountId = cmd .getAccountId ();
915915 final Long domainId = cmd .getDomainId ();
916916 final Long imageStoreId = cmd .getImageStoreId ();
917+ ConfigKey <?> configKey = null ;
917918 Optional optionalValue ;
918- final ConfigKey <?> configKey = _configDepot .get (name );
919- if (configKey == null ) {
920- s_logger .warn ("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface" );
921- throw new InvalidParameterValueException ("Config parameter with name " + name + " doesn't exist" );
919+ String defaultValue ;
920+ String category ;
921+ String configScope ;
922+ final ConfigurationVO config = _configDao .findByName (name );
923+ if (config == null ) {
924+ configKey = _configDepot .get (name );
925+ if (configKey == null ) {
926+ s_logger .warn ("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface" );
927+ throw new InvalidParameterValueException ("Config parameter with name " + name + " doesn't exist" );
928+ }
929+ defaultValue = configKey .defaultValue ();
930+ category = configKey .category ();
931+ configScope = configKey .scope ().toString ();
932+ } else {
933+ defaultValue = config .getDefaultValue ();
934+ category = config .getCategory ();
935+ configScope = config .getScope ();
922936 }
923- String defaultValue = configKey .defaultValue ();
924- String category = configKey .category ();
925- String configScope = configKey .scope ().toString ();
926937
927938 String scope = "" ;
928939 Map <String , Long > scopeMap = new LinkedHashMap <>();
@@ -958,7 +969,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
958969 throw new InvalidParameterValueException ("unable to find zone by id " + id );
959970 }
960971 _dcDetailsDao .removeDetail (id , name );
961- optionalValue = Optional .ofNullable (configKey .valueIn (id ));
972+ optionalValue = Optional .ofNullable (configKey != null ? configKey .valueIn (id ): config . getValue ( ));
962973 newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
963974 break ;
964975
@@ -968,13 +979,13 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
968979 throw new InvalidParameterValueException ("unable to find cluster by id " + id );
969980 }
970981 ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao .findDetail (id , name );
971- newValue = configKey .value ().toString ();
982+ newValue = configKey != null ? configKey .value ().toString () : config . getValue ();
972983 if (name .equalsIgnoreCase ("cpu.overprovisioning.factor" ) || name .equalsIgnoreCase ("mem.overprovisioning.factor" )) {
973984 _clusterDetailsDao .persist (id , name , newValue );
974985 } else if (clusterDetailsVO != null ) {
975986 _clusterDetailsDao .remove (clusterDetailsVO .getId ());
976987 }
977- optionalValue = Optional .ofNullable (configKey .valueIn (id ));
988+ optionalValue = Optional .ofNullable (configKey != null ? configKey .valueIn (id ): config . getValue ( ));
978989 newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
979990 break ;
980991
@@ -984,7 +995,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
984995 throw new InvalidParameterValueException ("unable to find storage pool by id " + id );
985996 }
986997 _storagePoolDetailsDao .removeDetail (id , name );
987- optionalValue = Optional .ofNullable (configKey .valueIn (id ));
998+ optionalValue = Optional .ofNullable (configKey != null ? configKey .valueIn (id ) : config . getValue ( ));
988999 newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
9891000 break ;
9901001
@@ -997,7 +1008,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
9971008 if (domainDetailVO != null ) {
9981009 _domainDetailsDao .remove (domainDetailVO .getId ());
9991010 }
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 (accountDetailVO != null ) {
10111022 _accountDetailsDao .remove (accountDetailVO .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 (imageStoreDetailVO != null ) {
10241035 _imageStoreDetailsDao .remove (imageStoreDetailVO .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
@@ -1032,7 +1043,7 @@ public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) thr
10321043 s_logger .error ("Failed to reset configuration option, name: " + name + ", defaultValue:" + defaultValue );
10331044 throw new CloudRuntimeException ("Failed to reset configuration value. Please contact Cloud Support." );
10341045 }
1035- optionalValue = Optional .ofNullable (configKey .value ());
1046+ optionalValue = Optional .ofNullable (configKey != null ? configKey .value () : config . getValue ());
10361047 newValue = optionalValue .isPresent () ? optionalValue .get ().toString () : defaultValue ;
10371048 }
10381049
0 commit comments