@Override public Map<String, String> setInstances( final String applicationName, final String serviceName, final int count, final int timeout) throws CLIException { final String url = SERVICE_CONTROLLER_URL + "applications/" + applicationName + "/services/" + serviceName + "/timeout/" + timeout + "/set-instances?count=" + count; try { @SuppressWarnings("unchecked") Map<String, String> response = (Map<String, String>) client.post(url); return response; } catch (final ErrorStatusException e) { throw new CLIStatusException(e, e.getReasonCode(), e.getArgs()); } catch (final RestException e) { throw new CLIException(e); } }
/** {@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; }
/** {@inheritDoc} */ @Override public void addInstance(final String applicationName, final String serviceName, final int timeout) throws CLIException { final String url = SERVICE_CONTROLLER_URL + "applications/na/services/" + serviceName + "/addinstance"; final Map<String, String> params = new HashMap<String, String>(); try { params.put("timeout", Integer.toString(timeout)); client.post(url, params); } catch (final ErrorStatusException e) { throw new CLIStatusException(e, e.getReasonCode(), e.getArgs()); } catch (final RestException e) { throw new CLIException(e); } }
/** {@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); }