@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; } }
@Override public void execute() { try { List<? extends Host> result = _resourceService.discoverHosts(this); ListResponse<HostResponse> response = new ListResponse<HostResponse>(); List<HostResponse> hostResponses = new ArrayList<HostResponse>(); if (result != null && result.size() > 0) { for (Host host : result) { HostResponse hostResponse = _responseGenerator.createHostResponse(host); hostResponses.add(hostResponse); } } else { throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add host"); } response.setResponses(hostResponses); response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (DiscoveryException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); } }