Ejemplo n.º 1
0
    public Object invoke(Object[] args) throws Exception {
      if (!LazyLoadScenario.isShouldLoad()) return null;

      Configuration parameters =
          ConfigurationClassBuilder.translateParametersToConfig(
              definition.getParametersConfigurationDefinition(), args);

      ResourceOperationSchedule schedule =
          remoteClient
              .getOperationManager()
              .scheduleResourceOperation(
                  remoteClient.getSubject(),
                  resourceId,
                  definition.getName(),
                  0,
                  0,
                  0,
                  30000,
                  parameters,
                  "Executed from commandline");

      ResourceOperationHistoryCriteria criteria = new ResourceOperationHistoryCriteria();
      criteria.addFilterJobId(schedule.getJobId());
      criteria.addFilterResourceIds(resourceId);
      criteria.addSortStartTime(PageOrdering.DESC); // put most recent at top of results
      criteria.setPaging(0, 1); // only return one result, in effect the latest
      criteria.fetchOperationDefinition(true);
      criteria.fetchParameters(true);
      criteria.fetchResults(true);

      int retries = 10;
      ResourceOperationHistory history = null;
      while (history == null && retries-- > 0) {
        Thread.sleep(1000);
        PageList<ResourceOperationHistory> histories =
            remoteClient
                .getOperationManager()
                .findResourceOperationHistoriesByCriteria(remoteClient.getSubject(), criteria);
        if (histories.size() > 0
            && histories.get(0).getStatus() != OperationRequestStatus.INPROGRESS) {
          history = histories.get(0);
        }
      }

      Configuration result = (history != null ? history.getResults() : null);

      Object returnResults =
          ConfigurationClassBuilder.translateResults(
              definition.getResultsConfigurationDefinition(), result);

      return returnResults;
    }
Ejemplo 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;
 }