public void testService(
      String serviceFolderPath, String overrideServiceName, final int timeoutMins)
      throws IOException, InterruptedException, RestException, PackagingException, DSLException {
    LogUtils.log("Reading Service from file : " + serviceFolderPath);
    Service service = ServiceReader.readService(new File(serviceFolderPath));
    LogUtils.log("Succesfully read Service : " + service);

    serviceName = service.getName();

    if (overrideServiceName != null) {
      LogUtils.log("Overriding service name with " + overrideServiceName);
      serviceName = overrideServiceName;
    }

    installServiceAndWait(serviceFolderPath, serviceName, timeoutMins);
    String restUrl = getRestUrl();
    GSRestClient client =
        new GSRestClient("", "", new URL(restUrl), PlatformVersion.getVersionNumber());
    Map<String, Object> entriesJsonMap =
        client.getAdminData("ProcessingUnits/Names/default." + serviceName + "/Status");
    String serviceStatus = (String) entriesJsonMap.get(STATUS_PROPERTY);

    AssertUtils.assertTrue("service is not intact", serviceStatus.equalsIgnoreCase("INTACT"));

    uninstallServiceAndWait(serviceName);
  }
Ejemplo n.º 2
0
  @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);
    }
  }
Ejemplo n.º 3
0
 @Override
 public String getTailByHostAddress(
     final String serviceName,
     final String applicationName,
     final String hostAddress,
     final int numLines)
     throws CLIException {
   final String url =
       SERVICE_CONTROLLER_URL
           + "applications/"
           + applicationName
           + "/services/"
           + serviceName
           + "/address/"
           + hostAddress
           + "/lines/"
           + numLines
           + "/tail";
   try {
     @SuppressWarnings("unchecked")
     String response = (String) client.get(url);
     return response;
   } catch (final ErrorStatusException e) {
     throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
   }
 }
Ejemplo n.º 4
0
  /** {@inheritDoc} */
  @Override
  public String installElastic(
      final File packedFile,
      final String applicationName,
      final String serviceName,
      final String zone,
      final Properties contextProperties,
      final String templateName,
      int timeout)
      throws CLIException {

    final String url =
        SERVICE_CONTROLLER_URL
            + "applications/"
            + applicationName
            + "/services/"
            + serviceName
            + "/timeout/"
            + timeout
            + "?zone="
            + zone
            + "&template="
            + templateName;
    try {
      return (String) client.postFile(url, packedFile, contextProperties);
    } catch (final ErrorStatusException e) {
      throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
    } catch (final RestException e) {
      throw new CLIException(e);
    }
  }
Ejemplo n.º 5
0
  /** {@inheritDoc} */
  @Override
  public void doConnect(final String user, final String password, final String url)
      throws CLIException {
    String formattedURL = url;
    if (!formattedURL.endsWith("/")) {
      formattedURL = formattedURL + '/';
    }
    if (!formattedURL.startsWith("http://")) {
      formattedURL = "http://" + formattedURL;
    }

    URL urlObj;
    try {
      urlObj = new URL(formattedURL);
      if (urlObj.getPort() == -1) {
        urlObj = getUrlWithDefaultPort(urlObj);
      }
    } catch (final MalformedURLException e) {
      throw new CLIStatusException("could_not_parse_url", url, e);
    }

    try {
      client = new GSRestClient(user, password, urlObj);
      // test connection
      client.get(SERVICE_CONTROLLER_URL + "testrest");
    } catch (final ErrorStatusException e) {
      throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
    } catch (final RestException e) {
      throw new CLIException(e);
    }
  }
Ejemplo n.º 6
0
 /** {@inheritDoc} */
 @Override
 public List<String> getApplicationsList() throws CLIException {
   try {
     @SuppressWarnings("unchecked")
     List<String> applications = (List<String>) client.get("/service/applications");
     return applications;
   } catch (final ErrorStatusException e) {
     throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
   }
 }
Ejemplo n.º 7
0
  /** {@inheritDoc} */
  public Map<String, String> dumpAgent(final String ip) throws CLIException {

    final String url = SERVICE_CONTROLLER_URL + "dump/" + ip;
    try {
      @SuppressWarnings("unchecked")
      Map<String, String> response = (Map<String, String>) client.get(url);
      return response;
    } catch (final ErrorStatusException e) {
      throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
    }
  }
Ejemplo n.º 8
0
 /** {@inheritDoc} */
 @Override
 public List<String> getServicesList(final String applicationName) throws CLIException {
   try {
     @SuppressWarnings("unchecked")
     List<String> services =
         (List<String>) client.get("/service/applications/" + applicationName + "/services");
     return services;
   } catch (final ErrorStatusException ese) {
     throw new CLIStatusException(ese, ese.getReasonCode(), ese.getArgs());
   }
 }
Ejemplo n.º 9
0
 /** {@inheritDoc} */
 @Override
 protected String doDeploy(final String applicationName, final File packedFile)
     throws CLIException {
   final String url =
       SERVICE_CONTROLLER_URL + CLOUD_CONTROLLER_URL + "deploy?applicationName=" + applicationName;
   try {
     return (String) client.postFile(url, packedFile);
   } catch (final ErrorStatusException e) {
     throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
   } catch (final RestException e) {
     throw new CLIException(e);
   }
 }
Ejemplo n.º 10
0
  /** {@inheritDoc} */
  @Override
  public Map<String, String> uninstallApplication(
      final String applicationName, int timeoutInMinutes) throws CLIException {

    final String url =
        SERVICE_CONTROLLER_URL + "applications/" + applicationName + "/timeout/" + timeoutInMinutes;
    try {
      @SuppressWarnings("unchecked")
      Map<String, String> response = (Map<String, String>) client.delete(url);
      return response;
    } catch (final ErrorStatusException e) {
      throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
    }
  }
Ejemplo n.º 11
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;
  }
Ejemplo n.º 12
0
  /** {@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);
    }
  }
Ejemplo n.º 13
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);

  }
Ejemplo n.º 14
0
 /**
  * Gets the UIDs of all GSCs.
  *
  * @return a set of UIDs
  * @throws CLIException Reporting a failure to locate the requested GSCs or get the UIDs.
  */
 public Set<String> getGridServiceContainerUids() throws CLIException {
   Map<String, Object> container;
   try {
     container = client.getAdmin("GridServiceContainers");
   } catch (final ErrorStatusException e) {
     throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
   } catch (final RestException e) {
     throw new CLIException(e);
   }
   @SuppressWarnings("unchecked")
   final List<String> containerUris = (List<String>) container.get("Uids-Elements");
   final Set<String> containerUids = new HashSet<String>();
   for (final String containerUri : containerUris) {
     final String uid = containerUri.substring(containerUri.lastIndexOf('/') + 1);
     containerUids.add(uid);
   }
   return containerUids;
 }
Ejemplo n.º 15
0
  /** {@inheritDoc} */
  @Override
  public Map<String, Object> getInstanceList(final String applicationName, final String serviceName)
      throws CLIException {

    final String url =
        SERVICE_CONTROLLER_URL
            + "applications/"
            + applicationName
            + "/services/"
            + serviceName
            + "/instances";
    try {
      @SuppressWarnings("unchecked")
      Map<String, Object> instances = (Map<String, Object>) client.get(url);
      return instances;
    } catch (final ErrorStatusException e) {
      throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
    }
  }
Ejemplo n.º 16
0
  /** {@inheritDoc} */
  @Override
  public void removeInstance(
      final String applicationName, final String serviceName, final int instanceId)
      throws CLIException {

    final String relativeUrl =
        SERVICE_CONTROLLER_URL
            + "applications/"
            + applicationName
            + "/services/"
            + serviceName
            + "/instances/"
            + instanceId
            + "/remove";
    try {
      client.delete(relativeUrl);
    } catch (final ErrorStatusException e) {
      throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
    }
  }
Ejemplo n.º 17
0
  /** {@inheritDoc} */
  @Override
  public List<String> getMachines() throws CLIException {

    Map<String, Object> map;
    try {
      map = client.getAdminData("machines/HostsByAddress");
    } catch (final ErrorStatusException e) {
      throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
    } catch (final RestException e) {
      throw new CLIException(e);
    }
    @SuppressWarnings("unchecked")
    final List<String> list = (List<String>) map.get("HostsByAddress-Elements");
    final List<String> result = new ArrayList<String>(list.size());
    for (final String host : list) {
      final String[] parts = host.split("/");
      final String ip = parts[parts.length - 1];
      result.add(ip);
    }
    return result;
  }
Ejemplo n.º 18
0
  /**
   * Returns all the UIDs of the GSCs that run the given service, in the context of the given
   * application.
   *
   * @param applicationName The name of the application deployed in the requested GSCs
   * @param serviceName The name of the service deployed in the requested GSCs
   * @return a set of UIDs of the GSCs that run the given service in the context of the given
   *     application
   * @throws CLIException Reporting a failure to locate the requested GSCs or get the UIDs.
   */
  public Set<String> getGridServiceContainerUidsForService(
      final String applicationName, final String serviceName) throws CLIException {

    final Set<String> containerUids = new HashSet<String>();

    final int numberOfInstances = this.getInstanceList(applicationName, serviceName).size();

    final String absolutePUName = ServiceUtils.getAbsolutePUName(applicationName, serviceName);
    for (int i = 0; i < numberOfInstances; i++) {

      final String containerUrl =
          "applications/Names/"
              + applicationName
              + "/ProcessingUnits/Names/"
              + absolutePUName
              + "/Instances/"
              + i
              + "/GridServiceContainer/Uid";
      try {
        final Map<String, Object> container = client.getAdmin(containerUrl);

        if (container == null) {
          throw new IllegalStateException("Could not find container " + containerUrl);
        }
        if (!container.containsKey("Uid")) {
          throw new IllegalStateException("Could not find AgentUid of container " + containerUrl);
        }

        containerUids.add((String) container.get("Uid"));
      } catch (final ErrorStatusException e) {
        throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
      } catch (final RestException e) {
        throw new CLIStatusException("cant_find_service_for_app", serviceName, applicationName);
      }
    }
    return containerUids;
  }