/**
   * Gets the latest events of this deployment id. Events are sorted by event index.
   *
   * @return A list of events. If this is the first time events are requested, all events are
   *     retrieved. Otherwise, only new events (that were not reported earlier) are retrieved.
   * @throws RestClientException Indicates a failure to get events from the server.
   */
  @Override
  public boolean lifeCycleEnded() throws RestClientException, CLIException {

    boolean serviceIsInstalled;
    try {
      ServiceDescription serviceDescription =
          restClient.getServiceDescription(applicationName, serviceName);
      logger.fine("Service description is : " + serviceDescription);
      CloudifyConstants.DeploymentState serviceState = serviceDescription.getServiceState();
      if (serviceState.equals(CloudifyConstants.DeploymentState.FAILED)) {
        throw new CLIException(
            ShellUtils.getFormattedMessage(
                CloudifyErrorMessages.FAILED_TO_DEPLOY_SERVICE.getName(), serviceName));
      }
      serviceIsInstalled = serviceState.equals(CloudifyConstants.DeploymentState.STARTED);
    } catch (final RestClientResponseException e) {
      if (e.getStatusCode() == RESOURCE_NOT_FOUND_EXCEPTION_CODE) {
        // the service is not available yet
        serviceIsInstalled = false;
      } else {
        throw e;
      }
    }

    return serviceIsInstalled;
  }
  @Override
  public int getNumberOfRunningInstances(final String serviceName) throws RestClientException {
    int instanceCount;
    try {
      ServiceDescription serviceDescription =
          restClient.getServiceDescription(applicationName, serviceName);
      instanceCount = serviceDescription.getInstanceCount();
    } catch (final RestClientResponseException e) {
      if (e.getStatusCode() == RESOURCE_NOT_FOUND_EXCEPTION_CODE) {
        // if we got here - the service is not installed yet
        instanceCount = 0;
      } else {
        throw e;
      }
    }

    return instanceCount;
  }