/* * Ensures that the proposed value is valid based on the set of valid values for OSGs * Additional DB lookup required for remote OSGs where the CLC doesn't have the OSG bits * installed and therefore doesn't have the same view of the set of valid values. * (non-Javadoc) * @see com.eucalyptus.configurable.PropertyChangeListener#fireChange(com.eucalyptus.configurable.ConfigurableProperty, java.lang.Object) */ @Override public void fireChange(ConfigurableProperty t, String newValue) throws ConfigurablePropertyException { String existingValue = (String) t.getValue(); List<ServiceConfiguration> objConfigs = null; try { objConfigs = ServiceConfigurations.list(ObjectStorage.class); } catch (NoSuchElementException e) { throw new ConfigurablePropertyException("No ObjectStorage configurations found"); } final String proposedValue = newValue; final Set<String> validEntries = Sets.newHashSet(); EntityTransaction tx = Entities.get(ObjectStorageConfiguration.class); try { if (!Iterables.any( Components.lookup(ObjectStorage.class).services(), new Predicate<ServiceConfiguration>() { @Override public boolean apply(ServiceConfiguration config) { if (config.isVmLocal()) { // Service is local, so add entries to the valid list (in case of HA configs) // and then check the local memory state validEntries.addAll(ObjectStorageProviders.list()); return ObjectStorageProviders.contains(proposedValue); } else { try { // Remote SC, so check the db for the list of valid entries. ObjectStorageConfiguration objConfig = Entities.uniqueResult((ObjectStorageConfiguration) config); for (String entry : Splitter.on(",").split(objConfig.getAvailableClients())) { validEntries.add(entry); } return validEntries.contains(proposedValue); } catch (Exception e) { return false; } } } })) { // Nothing matched. throw new ConfigurablePropertyException( "Cannot modify " + t.getQualifiedName() + "." + t.getFieldName() + " new value is not a valid value. " + "Legal values are: " + Joiner.on(",").join(validEntries)); } } finally { tx.rollback(); } }
public static ModifyPropertyValueResponseType modifyProperty(ModifyPropertyValueType request) throws EucalyptusCloudException { ModifyPropertyValueResponseType reply = request.getReply(); if (INTERNAL_OP.equals(request.getName())) { if (!Contexts.lookup().hasAdministrativePrivileges()) { throw new EucalyptusCloudException("You are not authorized to interact with this service."); } LOG.debug("Performing euca operation: \n" + request.getValue()); try { reply.setName(INTERNAL_OP); reply.setValue("" + Groovyness.eval(request.getValue())); reply.setOldValue("executed successfully."); } catch (Exception ex) { LOG.error(ex, ex); reply.setName(INTERNAL_OP); reply.setOldValue("euca operation failed because of: " + ex.getMessage()); reply.setValue(Exceptions.string(ex)); } } else { try { ConfigurableProperty entry = PropertyDirectory.getPropertyEntry(request.getName()); String oldValue = "********"; if (!entry.getWidgetType().equals(ConfigurableFieldType.KEYVALUEHIDDEN)) { oldValue = entry.getValue(); } reply.setOldValue(oldValue); Boolean reset = request.getReset(); if (reset != null) { if (Boolean.TRUE.equals(reset)) { entry.setValue(entry.getDefaultValue()); } } else { // if property is ReadOnly it should not be set by user if (!entry.getReadOnly()) { try { String inValue = request.getValue(); entry.setValue((inValue == null) ? "" : inValue); } catch (Exception e) { entry.setValue(oldValue); Exceptions.findAndRethrow(e, EucalyptusCloudException.class); throw e; } } } reply.setValue(entry.getValue()); reply.setName(request.getName()); } catch (IllegalAccessException e) { throw new EucalyptusCloudException("Failed to set property: " + e.getMessage()); } catch (EucalyptusCloudException e) { throw e; } catch (Throwable e) { throw new EucalyptusCloudException(e); } } return reply; }
public Address allocateNext(final OwnerFullName userId) throws NotEnoughResourcesException { int numSystemReserved = 0; try { ConfigurableProperty p = PropertyDirectory.getPropertyEntry("cloud.addresses.systemreservedpublicaddresses"); if (p != null) numSystemReserved = Integer.parseInt(p.getValue()); } catch (IllegalAccessException e) { LOG.error("Can't find the 'systemreservedpublicaddresses' property"); numSystemReserved = 0; } if ((Addresses.getInstance().listDisabledValues().size() - numSystemReserved) < 1) { throw new NotEnoughResourcesException(ExceptionList.ERR_SYS_INSUFFICIENT_ADDRESS_CAPACITY); } Predicate<Address> predicate = RestrictedTypes.filterPrivileged(); final Address addr = Addresses.getInstance().enableFirst(predicate).allocate(userId); LOG.debug("Allocated address for public addressing: " + addr.toString()); if (addr == null) { LOG.debug(LogUtil.header(Addresses.getInstance().toString())); throw new NotEnoughResourcesException(ExceptionList.ERR_SYS_INSUFFICIENT_ADDRESS_CAPACITY); } return addr; }
@Override public void fireChange(ConfigurableProperty t, Object newValue) throws ConfigurablePropertyException { try { if ("false".equals(((String) newValue).toLowerCase()) && "true".equals(t.getValue())) { try { if (ImagingServiceLaunchers.getInstance().shouldDisable()) ImagingServiceLaunchers.getInstance().disable(); } catch (ConfigurablePropertyException ex) { throw ex; } catch (Exception ex) { throw ex; } } else if ("true".equals((String) newValue)) {; } else throw new ConfigurablePropertyException("Invalid property value"); } catch (final ConfigurablePropertyException ex) { throw ex; } catch (final Exception e) { throw new ConfigurablePropertyException("Could not disable imaging service workers", e); } }
public static DescribePropertiesResponseType describeProperties( final DescribePropertiesType request) throws EucalyptusCloudException { DescribePropertiesResponseType reply = request.getReply(); List<Property> props = reply.getProperties(); final Predicate<ConfigurableProperty> filter = new Predicate<ConfigurableProperty>() { public boolean apply(final ConfigurableProperty input) { if (request.getProperties().isEmpty()) { return true; } else if (request.getProperties().contains(input.getQualifiedName())) { return true; } else { for (String propRequest : request.getProperties()) { if (input.getQualifiedName().startsWith(propRequest)) { return true; } } } return false; } }; for (ConfigurableProperty entry : Iterables.filter(PropertyDirectory.getPropertyEntrySet(), filter)) { if (filter.apply(entry)) { String value = "********"; if (!entry.getWidgetType().equals(ConfigurableFieldType.KEYVALUEHIDDEN)) value = entry.getValue(); props.add( new Property( entry.getQualifiedName(), value, entry.getDescription(), entry.getDefaultValue(), entry.getReadOnly())); } } return reply; }
@Override public void fireChange(ConfigurableProperty t, String newValue) throws ConfigurablePropertyException { String existingValue = (String) t.getValue(); if (existingValue != null && !"<unset>".equals(existingValue)) { throw new ConfigurablePropertyException( "Cannot change extant storage backend configuration. You must deregister all SCs in the partition before you can change the configuration value"); } else { // Try to figure out the partition name for the request String probablePartitionName = ((MultiDatabasePropertyEntry) t).getEntrySetName(); if (probablePartitionName == null) { throw new ConfigurablePropertyException( "Could not determing partition name from property to check validity"); } String[] parts = probablePartitionName.split("\\."); if (parts == null || parts.length == 0) { throw new ConfigurablePropertyException( "Could not determing partition name from property to check validity: " + probablePartitionName); } probablePartitionName = parts[0]; /*Look through the service configurations for each SC in the partition and see if the value is valid. * This step must work if we don't allow the user to change it once set. * The difficulty here is if 2 SCs are in an HA pair but have different backends installed (i.e. packages) * The implemented semantic is that if the proposed value is valid in either SC, then allow the change. */ List<ServiceConfiguration> scConfigs = null; try { scConfigs = ServiceConfigurations.listPartition(Storage.class, probablePartitionName); } catch (NoSuchElementException e) { throw new ConfigurablePropertyException( "No Storage Controller configurations found for partition: " + probablePartitionName); } final String proposedValue = newValue; final Set<String> validEntries = Sets.newHashSet(); EntityTransaction tx = Entities.get(StorageControllerConfiguration.class); try { if (!Iterables.any( scConfigs, new Predicate<ServiceConfiguration>() { @Override public boolean apply(ServiceConfiguration config) { if (config.isVmLocal()) { // Service is local, so add entries to the valid list (in case of HA configs) // and then check the local memory state validEntries.addAll(StorageManagers.list()); return StorageManagers.contains(proposedValue); } else { try { // Remote SC, so check the db for the list of valid entries. StorageControllerConfiguration scConfig = Entities.uniqueResult((StorageControllerConfiguration) config); for (String entry : Splitter.on(",").split(scConfig.getAvailableBackends())) { validEntries.add(entry); } return validEntries.contains(proposedValue); } catch (Exception e) { return false; } } } })) { // Nothing matched. throw new ConfigurablePropertyException( "Cannot modify " + t.getQualifiedName() + "." + t.getFieldName() + " new value is not a valid value. " + "Legal values are: " + Joiner.on(",").join(validEntries)); } } finally { tx.rollback(); } } }