Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 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;
 }