@Test
  public void testExecuteForNullResult() {

    ResourceService resourceService = Mockito.mock(ResourceService.class);

    try {
      Mockito.when(resourceService.discoverCluster(addClusterCmd)).thenReturn(null);
    } catch (ResourceInUseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (DiscoveryException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    addClusterCmd._resourceService = resourceService;

    try {
      addClusterCmd.execute();
    } catch (ServerApiException exception) {
      Assert.assertEquals("Failed to add cluster", exception.getDescription());
    }
  }
 @Override
 public void execute()
     throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException,
         ConcurrentOperationException, ResourceAllocationException {
   try {
     netappMgr.destroyVolumeOnFiler(ipAddr, aggrName, volumeName);
     DeleteVolumeOnFilerCmdResponse response = new DeleteVolumeOnFilerCmdResponse();
     response.setResponseName(getCommandName());
     this.setResponseObject(response);
   } catch (InvalidParameterValueException e) {
     throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString());
   } catch (ResourceInUseException e) {
     throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, e.toString());
   } catch (ServerException e) {
     throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString());
   }
 }
Ejemplo n.º 3
0
  @Override
  public void execute() {
    try {
      if ((getRamOvercommitRaito().compareTo(1f) <= 0)
          | (getCpuOvercommitRatio().compareTo(1f) <= 0)) {
        throw new InvalidParameterValueException(
            "Cpu and ram overcommit ratios  should not be less than 1");
      }
      List<? extends Cluster> result = _resourceService.discoverCluster(this);
      ListResponse<ClusterResponse> response = new ListResponse<ClusterResponse>();
      List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();
      if (result != null && result.size() > 0) {
        for (Cluster cluster : result) {
          ClusterResponse clusterResponse =
              _responseGenerator.createClusterResponse(cluster, false);
          clusterResponses.add(clusterResponse);
        }
      } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add cluster");
      }

      response.setResponses(clusterResponses);
      response.setResponseName(getCommandName());

      this.setResponseObject(response);
    } catch (DiscoveryException ex) {
      s_logger.warn("Exception: ", ex);
      throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (ResourceInUseException ex) {
      s_logger.warn("Exception: ", ex);
      ServerApiException e = new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
      for (String proxyObj : ex.getIdProxyList()) {
        e.addProxyObject(proxyObj);
      }
      throw e;
    }
  }