Exemplo n.º 1
0
  public static void convertManagedOperationResults(
      ManagedOperation operation,
      MetaValue resultMetaValue,
      Configuration complexResults,
      OperationDefinition operationDefinition) {
    ConfigurationDefinition resultConfigDef =
        operationDefinition.getResultsConfigurationDefinition();
    // Don't return any results if we have no definition with which to display them
    if (resultConfigDef == null || resultConfigDef.getPropertyDefinitions().isEmpty()) {
      if (resultMetaValue != null) {
        LOG.error(
            "Plugin error: Operation ["
                + operationDefinition.getName()
                + "] is defined as returning no results, but it returned non-null results: "
                + resultMetaValue.toString());
      }
      return;
    } else {
      Map<String, PropertyDefinition> resultPropDefs = resultConfigDef.getPropertyDefinitions();
      // There should and must be only one property definition to map to the results from the
      // Profile Service,
      // otherwise there will be a huge mismatch.
      if (resultPropDefs.size() > 1)
        LOG.error(
            "Operation ["
                + operationDefinition.getName()
                + "] is defined with multiple result properties: "
                + resultPropDefs.values());

      PropertyDefinition resultPropDef = resultPropDefs.values().iterator().next();

      // Don't return any results, if the actual result object is null.
      if (resultMetaValue == null) {
        // Check if result is required or not, and if it is, log an error.
        if (resultPropDef.isRequired()) {
          LOG.error(
              "Plugin error: Operation ["
                  + operationDefinition.getName()
                  + "] is defined as returning a required result, but it returned null.");
        }
        return;
      }

      MetaType resultMetaType = operation.getReturnType();
      if (!MetaTypeUtils.instanceOf(resultMetaValue, resultMetaType))
        LOG.debug(
            "Profile Service Error: Result type ("
                + resultMetaType
                + ") of ["
                + operation.getName()
                + "] ManagedOperation does not match the type of the value returned by invoke() ("
                + resultMetaValue
                + ").");

      PropertyAdapter propertyAdapter = PropertyAdapterFactory.getPropertyAdapter(resultMetaValue);
      Property resultProp = propertyAdapter.convertToProperty(resultMetaValue, resultPropDef);
      complexResults.put(resultProp);
    }
  }
Exemplo n.º 2
0
 /**
  * Takes the Configuration parameter object and converts it into a MetaValue array, which can them
  * be passed in with the invoke method to the ProfileService to fire the operation of a resource.
  *
  * @param managedOperation Operation that will be fired and stores the parameter types for the
  *     operation
  * @param parameters set of Parameter Values that the OperationFacet sent to the Component
  * @param operationDefinition the RHQ operation definition
  * @return MetaValue[] array of MetaValues representing the parameters; if there are no
  *     parameters, an empty array will be returned
  */
 @NotNull
 public static MetaValue[] convertOperationsParametersToMetaValues(
     @NotNull ManagedOperation managedOperation,
     @NotNull Configuration parameters,
     @NotNull OperationDefinition operationDefinition) {
   ConfigurationDefinition paramsConfigDef =
       operationDefinition.getParametersConfigurationDefinition();
   if (paramsConfigDef == null) return new MetaValue[0];
   ManagedParameter[] managedParams =
       managedOperation.getParameters(); // this is guaranteed to be non-null
   Map<String, PropertyDefinition> paramPropDefs = paramsConfigDef.getPropertyDefinitions();
   MetaValue[] paramMetaValues = new MetaValue[managedParams.length];
   for (int i = 0; i < managedParams.length; i++) {
     ManagedParameter managedParam = managedParams[i];
     String paramName = managedParam.getName();
     Property paramProp = parameters.get(paramName);
     PropertyDefinition paramPropDef = paramPropDefs.get(paramName);
     MetaType metaType = managedParam.getMetaType();
     PropertyAdapter propertyAdapter = PropertyAdapterFactory.getPropertyAdapter(metaType);
     LOG.trace(
         "Converting RHQ operation param property "
             + paramProp
             + " with definition "
             + paramPropDef
             + " to MetaValue of type "
             + metaType
             + "...");
     MetaValue paramMetaValue =
         propertyAdapter.convertToMetaValue(paramProp, paramPropDef, metaType);
     // NOTE: There's no need to set the value on the ManagedParameter, since the invoke() API
     // takes an array of
     //       MetaValues.
     paramMetaValues[i] = paramMetaValue;
   }
   return paramMetaValues;
 }