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

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

    return invocationResult;
  }
Пример #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;
  }
Пример #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);

  }
  @Test(timeOut = AbstractTestSupport.DEFAULT_TEST_TIMEOUT * 4, enabled = true)
  public void testXAP9xRecipe() throws Exception {
    InvocationResult result;
    InvokeServiceCommandResponse response;

    // Install and verify xap-management
    String installationLog =
        installApplicationAndWait(
            XAP9X_PATH, APP_NAME); // installAndVerify(XAP9X_MANAGEMENT_PATH,XAP9X_MANAGEMENT);
    verifyPUInstallation(APP_NAME);
    Pattern pattern =
        Pattern.compile(
            "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}] - xap-management-1 START invoked"); // Regex for ip to match in the log of xap-management installation
    Matcher matcher = pattern.matcher(installationLog);
    if (!matcher.find()) {
      throw new Exception("Unable to find lookuplocator's ip in the log: " + installationLog);
    }
    String managementPrivateIP = matcher.group(0);
    String lookuplocators =
        managementPrivateIP.substring(
                managementPrivateIP.indexOf("/") + 1, managementPrivateIP.indexOf("]"))
            + ":4242";
    log("Using lookuplocators: " + lookuplocators);
    // Install and verify sgvalidator
    installAndVerify(SG_VALIDATOR_PATH, SG_VALIDATOR);

    // First validate and undeploy myDataGrid that the container-service deploy
    validateInstance(lookuplocators, DEPLOYGRID_MYDATAGRID_COMMAND);
    // undeploy-grid
    response = customCommand(UNDEPLOYGRID_MYDATAGRID_COMMAND, XAP9X_MANAGEMENT, APP_NAME);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);

    // deploy-pu
    response = customCommand(DEPLOYPU_COMMAND, XAP9X_MANAGEMENT, APP_NAME);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);
    validateInstance(lookuplocators, DEPLOYPU_COMMAND);
    // undeploy-grid
    response = customCommand(UNDEPLOYGRID_DEPLOYPU_COMMAND, XAP9X_MANAGEMENT, APP_NAME);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);

    // deploy-pu-basic
    response = customCommand(DEPLOYPUBASIC_COMMAND, XAP9X_MANAGEMENT, APP_NAME);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);
    validateInstance(lookuplocators, DEPLOYPUBASIC_COMMAND);
    // undeploy-grid
    response = customCommand(UNDEPLOYGRID_DEPLOYPUBASIC_COMMAND, XAP9X_MANAGEMENT, APP_NAME);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);

    // deploy-grid
    response = customCommand(DEPLOYGRID_COMMAND, XAP9X_MANAGEMENT, APP_NAME);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);
    validateInstance(lookuplocators, DEPLOYGRID_COMMAND);
    // undeploy-grid
    response = customCommand(UNDEPLOYGRID_DEPLOYGRID_COMMAND, XAP9X_MANAGEMENT, APP_NAME);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);

    // deploy-grid
    response = customCommand(DEPLOYGRIDBASIC_COMMAND, XAP9X_MANAGEMENT, APP_NAME);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);
    validateInstance(lookuplocators, DEPLOYGRIDBASIC_COMMAND);
    // undeploy-grid
    response = customCommand(UNDEPLOYGRID_DEPLOYGRIDBASIC_COMMAND, XAP9X_MANAGEMENT, APP_NAME);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);

    String uninstallOutput = uninstallAndVerify();
  }
  private void validateInstance(String lookuplocators, String deploypuCommand) throws Exception {
    String gridname;
    String partitions, backups, maxPerVM, maxPerMachine;
    String[] deployCmdArr = deploypuCommand.split(" ");
    if (deployCmdArr[0].equals("deploy-pu")) {
      gridname = deployCmdArr[1];
      partitions = deployCmdArr[4];
      backups = deployCmdArr[5];
      maxPerVM = deployCmdArr[6];
      maxPerMachine = deployCmdArr[7];
    } else if (deployCmdArr[0].equals("deploy-grid")) {
      gridname = deployCmdArr[1];
      partitions = deployCmdArr[3];
      backups = deployCmdArr[4];
      maxPerVM = deployCmdArr[5];
      maxPerMachine = deployCmdArr[6];
    } else if (deployCmdArr[0].equals("deploy-pu-basic")) {
      File file = new File(PUURL);
      gridname = file.getName();
      partitions = "1";
      backups = "0";
      maxPerVM = "1";
      maxPerMachine = "1";
    } else if (deployCmdArr[0].equals("deploy-grid-basic")) {
      gridname = deployCmdArr[1];
      partitions = "1";
      backups = "1";
      maxPerVM = "0";
      maxPerMachine = "0";
    } else {
      throw new Exception(
          "Unknown command. Please recheck the command or add it to validateInstance function.");
    }
    InvokeServiceCommandResponse response;
    InvocationResult result;
    String appName = "default";
    String numOfInstances =
        String.valueOf(Integer.valueOf(partitions) * (1 + Integer.valueOf(backups)));

    response =
        customCommand(
            "get-datagrid-instances " + gridname + " " + lookuplocators + " " + numOfInstances,
            SG_VALIDATOR,
            appName);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);
    Assert.assertEquals(result.getResult(), numOfInstances);

    response =
        customCommand(
            "get-datagrid-deploymentstatus "
                + gridname
                + " "
                + lookuplocators
                + " "
                + numOfInstances,
            SG_VALIDATOR,
            appName);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);
    Assert.assertEquals(result.getResult(), String.valueOf(DeploymentStatus.INTACT));

    response =
        customCommand(
            "get-datagrid-partitions " + gridname + " " + lookuplocators + " " + numOfInstances,
            SG_VALIDATOR,
            appName);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);
    Assert.assertEquals(result.getResult(), partitions);

    response =
        customCommand(
            "get-datagrid-backups " + gridname + " " + lookuplocators + " " + numOfInstances,
            SG_VALIDATOR,
            appName);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);
    Assert.assertEquals(result.getResult(), backups);

    response =
        customCommand(
            "get-datagrid-maxinstancespermachine "
                + gridname
                + " "
                + lookuplocators
                + " "
                + numOfInstances,
            SG_VALIDATOR,
            appName);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);
    Assert.assertEquals(result.getResult(), maxPerMachine);

    response =
        customCommand(
            "get-datagrid-maxinstancespervm "
                + gridname
                + " "
                + lookuplocators
                + " "
                + numOfInstances,
            SG_VALIDATOR,
            appName);
    result = getCustomCommandResult(response);
    Assert.assertEquals(result.getInvocationStatus(), CloudifyConstants.InvocationStatus.SUCCESS);
    Assert.assertEquals(result.getResult(), maxPerVM);
  }