Beispiel #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);
    }
  }
Beispiel #2
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;
    }