protected void cleanUpNetworksAndFirewallsForGroup(String groupName) {
    String resourceName = namingConvention.create().sharedNameForGroup(groupName);
    AtomicReference<Operation> operation =
        new AtomicReference<Operation>(
            api.getFirewallApiForProject(project.get()).delete(resourceName));

    retry(
            operationDonePredicate,
            operationCompleteCheckTimeout,
            operationCompleteCheckInterval,
            MILLISECONDS)
        .apply(operation);

    if (operation.get().getHttpError().isPresent()) {
      HttpResponse response = operation.get().getHttpError().get();
      logger.warn(
          "delete orphaned firewall failed. Http Error Code: "
              + response.getStatusCode()
              + " HttpError: "
              + response.getMessage());
    }

    operation =
        new AtomicReference<Operation>(
            api.getNetworkApiForProject(project.get()).delete(resourceName));

    retry(
            operationDonePredicate,
            operationCompleteCheckTimeout,
            operationCompleteCheckInterval,
            MILLISECONDS)
        .apply(operation);

    if (operation.get().getHttpError().isPresent()) {
      HttpResponse response = operation.get().getHttpError().get();
      logger.warn(
          "delete orphaned network failed. Http Error Code: "
              + response.getStatusCode()
              + " HttpError: "
              + response.getMessage());
    }
  }
Пример #2
0
  @Override
  public void handleError(final HttpCommand command, final HttpResponse response) {
    Exception exception = null;
    String defaultMessage =
        String.format(
            "%s -> %s", command.getCurrentRequest().getRequestLine(), response.getStatusLine());

    try {
      switch (response.getStatusCode()) {
        case 401:
        case 403:
          // Authorization exceptions do not return an errors DTO, so we
          // encapsulate a generic exception
          exception =
              new AuthorizationException(
                  defaultMessage, new HttpResponseException(command, response, defaultMessage));
          break;
        case 404:
          // TODO: get the exception to encapsulate from the returned error
          // object
          exception = new ResourceNotFoundException(defaultMessage);
          break;
        case 301:
          // Moved resources in Abiquo should be handled with the
          // ReturnMovedResource exception parser to return the moved
          // entity.
          exception = new HttpResponseException(command, response, defaultMessage);
          break;
        default:
          // TODO: get the exception to encapsulate from the returned error
          // object
          exception = new HttpResponseException(response.getMessage(), command, response);
          break;
      }
    } finally {
      closeQuietly(response.getPayload());
      command.setException(exception);
    }
  }