private InvocationResult parseInvocationResult(final Map<String, String> restInvocationResult) {

    InvocationResult invocationResult = null;
    if (restInvocationResult != null) {
      invocationResult = InvocationResult.createInvocationResult(restInvocationResult);
    }

    return invocationResult;
  }
Example #2
0
  /** {@inheritDoc} */
  @Override
  public Map<String, InvocationResult> invokeServiceCommand(
      final String applicationName,
      final String serviceName,
      final String beanName,
      final String commandName,
      final Map<String, String> params)
      throws CLIException {
    final String url =
        SERVICE_CONTROLLER_URL
            + "applications/"
            + applicationName
            + "/services/"
            + serviceName
            + "/beans/"
            + beanName
            + "/invoke";

    Object result;
    try {
      result = client.post(url, buildCustomCommandParams(commandName, params));
    } catch (final ErrorStatusException e) {
      throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
    } catch (final RestException e) {
      throw new CLIException(e);
    }

    @SuppressWarnings("unchecked")
    final Map<String, Object> restResult = (Map<String, Object>) result;

    final Map<String, InvocationResult> invocationResultMap =
        new LinkedHashMap<String, InvocationResult>();
    for (final Map.Entry<String, Object> entry : restResult.entrySet()) {
      final Object value = entry.getValue();

      if (!(value instanceof Map<?, ?>)) {
        logger.severe(
            "Received an unexpected return value to the invoke command. Key: "
                + entry.getKey()
                + ", value: "
                + value);
      } else {
        @SuppressWarnings("unchecked")
        final Map<String, String> curr = (Map<String, String>) value;
        final InvocationResult invocationResult = InvocationResult.createInvocationResult(curr);
        invocationResultMap.put(entry.getKey(), invocationResult);
      }
    }
    return invocationResultMap;
  }
Example #3
0
  /** {@inheritDoc} */
  @Override
  public InvocationResult invokeInstanceCommand(
      final String applicationName,
      final String serviceName,
      final String beanName,
      final int instanceId,
      final String commandName,
      final Map<String, String> paramsMap)
      throws CLIException {
    final String url =
        SERVICE_CONTROLLER_URL
            + "applications/"
            + applicationName
            + "/services/"
            + serviceName
            + "/instances/"
            + instanceId
            + "/beans/"
            + beanName
            + "/invoke";

    Map<String, String> resultMap;
    try {
      @SuppressWarnings("unchecked")
      Map<String, String> response =
          (Map<String, String>) client.post(url, buildCustomCommandParams(commandName, paramsMap));
      resultMap = response;
    } catch (final ErrorStatusException e) {
      throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
    } catch (final RestException e) {
      throw new CLIException(e);
    }

    // resultMap.entrySet().iterator().next();
    // InvocationResult invocationResult = InvocationResult
    // .createInvocationResult(resultMap);
    // @SuppressWarnings("unchecked")
    // Map<String, String> curr = (Map<String, String>) resultMap;
    // InvocationResult invocationResult = InvocationResult
    // .createInvocationResult(curr);
    //
    return InvocationResult.createInvocationResult(resultMap);
    // return GSRestClient.mapToInvocationResult(resultMap);

  }