Search in sources :

Example 16 with DiscoveryException

use of com.cloud.exception.DiscoveryException in project cloudstack by apache.

the class AddVmwareDcCmd method execute.

@Override
public void execute() {
    try {
        VmwareDatacenterResponse response = new VmwareDatacenterResponse();
        VmwareDatacenterVO result = _vmwareDatacenterService.addVmwareDatacenter(this);
        if (result != null) {
            response.setId(result.getUuid());
            response.setName(result.getVmwareDatacenterName());
            response.setResponseName(getCommandName());
            response.setObjectName("vmwaredc");
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add VMware Datacenter to zone.");
        }
        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;
    } catch (IllegalArgumentException ex) {
        throw new IllegalArgumentException(ex.getMessage());
    } catch (CloudRuntimeException runtimeEx) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeEx.getMessage());
    }
}
Also used : VmwareDatacenterResponse(org.apache.cloudstack.api.response.VmwareDatacenterResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) VmwareDatacenterVO(com.cloud.hypervisor.vmware.VmwareDatacenterVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceInUseException(com.cloud.exception.ResourceInUseException) DiscoveryException(com.cloud.exception.DiscoveryException)

Example 17 with DiscoveryException

use of com.cloud.exception.DiscoveryException in project cloudstack by apache.

the class SimulatorDiscoverer method find.

/**
     * Finds ServerResources of an in-process simulator
     *
     * @see com.cloud.resource.Discoverer#find(long, java.lang.Long,
     *      java.lang.Long, java.net.URI, java.lang.String, java.lang.String)
     */
@Override
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI uri, String username, String password, List<String> hostTags) throws DiscoveryException {
    Map<AgentResourceBase, Map<String, String>> resources;
    try {
        //http://sim/count=$count, it will add $count number of hosts into the cluster
        String scheme = uri.getScheme();
        String host = uri.getAuthority();
        String commands = URLDecoder.decode(uri.getPath());
        long cpuSpeed = MockAgentManager.DEFAULT_HOST_SPEED_MHZ;
        long cpuCores = MockAgentManager.DEFAULT_HOST_CPU_CORES;
        long memory = MockAgentManager.DEFAULT_HOST_MEM_SIZE;
        long localstorageSize = MockStorageManager.DEFAULT_HOST_STORAGE_SIZE;
        if (scheme.equals("http")) {
            if (host == null || !host.startsWith("sim")) {
                String msg = "uri is not of simulator type so we're not taking care of the discovery for this: " + uri;
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug(msg);
                }
                return null;
            }
            if (commands != null) {
                int index = commands.lastIndexOf("/");
                if (index != -1) {
                    commands = commands.substring(index + 1);
                    String[] cmds = commands.split("&");
                    for (String cmd : cmds) {
                        String[] parameter = cmd.split("=");
                        if (parameter[0].equalsIgnoreCase("cpuspeed") && parameter[1] != null) {
                            cpuSpeed = Long.parseLong(parameter[1]);
                        } else if (parameter[0].equalsIgnoreCase("cpucore") && parameter[1] != null) {
                            cpuCores = Long.parseLong(parameter[1]);
                        } else if (parameter[0].equalsIgnoreCase("memory") && parameter[1] != null) {
                            memory = Long.parseLong(parameter[1]);
                        } else if (parameter[0].equalsIgnoreCase("localstorage") && parameter[1] != null) {
                            localstorageSize = Long.parseLong(parameter[1]);
                        }
                    }
                }
            }
        } else {
            String msg = "uriString is not http so we're not taking care of the discovery for this: " + uri;
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(msg);
            }
            return null;
        }
        String cluster = null;
        if (clusterId == null) {
            String msg = "must specify cluster Id when adding host";
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(msg);
            }
            throw new RuntimeException(msg);
        } else {
            ClusterVO clu = _clusterDao.findById(clusterId);
            if (clu == null || (clu.getHypervisorType() != HypervisorType.Simulator)) {
                if (s_logger.isInfoEnabled())
                    s_logger.info("invalid cluster id or cluster is not for Simulator hypervisors");
                return null;
            }
            cluster = Long.toString(clusterId);
            if (clu.getGuid() == null) {
                clu.setGuid(UUID.randomUUID().toString());
            }
            _clusterDao.update(clusterId, clu);
        }
        String pod;
        if (podId == null) {
            String msg = "must specify pod Id when adding host";
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(msg);
            }
            throw new RuntimeException(msg);
        } else {
            pod = Long.toString(podId);
        }
        Map<String, String> details = new HashMap<String, String>();
        Map<String, Object> params = new HashMap<String, Object>();
        details.put("username", username);
        params.put("username", username);
        details.put("password", password);
        params.put("password", password);
        params.put("zone", Long.toString(dcId));
        params.put("pod", pod);
        params.put("cluster", cluster);
        params.put("cpuspeed", Long.toString(cpuSpeed));
        params.put("cpucore", Long.toString(cpuCores));
        params.put("memory", Long.toString(memory));
        params.put("localstorage", Long.toString(localstorageSize));
        resources = createAgentResources(params);
        return resources;
    } catch (Exception ex) {
        s_logger.error("Exception when discovering simulator hosts: " + ex.getMessage());
    }
    return null;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) HashMap(java.util.HashMap) DiscoveryException(com.cloud.exception.DiscoveryException) ConfigurationException(javax.naming.ConfigurationException) ConnectionException(com.cloud.exception.ConnectionException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with DiscoveryException

use of com.cloud.exception.DiscoveryException in project CloudStack-archive by CloudStack-extras.

the class AddClusterCmd method execute.

@Override
public void execute() {
    try {
        List<? extends Cluster> result = _resourceService.discoverCluster(this);
        ListResponse<ClusterResponse> response = new ListResponse<ClusterResponse>();
        List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();
        if (result != null) {
            for (Cluster cluster : result) {
                ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
                clusterResponses.add(clusterResponse);
            }
        } else {
            throw new ServerApiException(BaseCmd.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(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    } catch (ResourceInUseException ex) {
        s_logger.warn("Exception: ", ex);
        ServerApiException e = new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
        for (IdentityProxy proxyObj : ex.getIdProxyList()) {
            e.addProxyObject(proxyObj.getTableName(), proxyObj.getValue(), proxyObj.getidFieldName());
        }
        throw e;
    }
}
Also used : IdentityProxy(com.cloud.utils.IdentityProxy) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) ResourceInUseException(com.cloud.exception.ResourceInUseException) ArrayList(java.util.ArrayList) ClusterResponse(com.cloud.api.response.ClusterResponse) Cluster(com.cloud.org.Cluster) DiscoveryException(com.cloud.exception.DiscoveryException)

Example 19 with DiscoveryException

use of com.cloud.exception.DiscoveryException in project CloudStack-archive by CloudStack-extras.

the class AddHostCmd method execute.

@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());
    }
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) HostResponse(com.cloud.api.response.HostResponse) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host) DiscoveryException(com.cloud.exception.DiscoveryException)

Example 20 with DiscoveryException

use of com.cloud.exception.DiscoveryException in project CloudStack-archive by CloudStack-extras.

the class AddSwiftCmd method execute.

@Override
public void execute() {
    try {
        Swift result = _resourceService.discoverSwift(this);
        SwiftResponse swiftResponse = null;
        if (result != null) {
            swiftResponse = _responseGenerator.createSwiftResponse(result);
            swiftResponse.setResponseName(getCommandName());
            swiftResponse.setObjectName("swift");
            this.setResponseObject(swiftResponse);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Swift");
        }
    } catch (DiscoveryException ex) {
        String errMsg = "Failed to add Swift due to " + ex.toString();
        s_logger.warn(errMsg, ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, errMsg);
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) SwiftResponse(com.cloud.api.response.SwiftResponse) Swift(com.cloud.storage.Swift) DiscoveryException(com.cloud.exception.DiscoveryException)

Aggregations

DiscoveryException (com.cloud.exception.DiscoveryException)29 HashMap (java.util.HashMap)15 ConfigurationException (javax.naming.ConfigurationException)14 ClusterVO (com.cloud.dc.ClusterVO)12 Map (java.util.Map)12 ResourceInUseException (com.cloud.exception.ResourceInUseException)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)9 DataCenterVO (com.cloud.dc.DataCenterVO)6 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)6 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 HostVO (com.cloud.host.HostVO)6 InetAddress (java.net.InetAddress)6 ArrayList (java.util.ArrayList)6 ConnectionException (com.cloud.exception.ConnectionException)5 DiscoveredWithErrorException (com.cloud.exception.DiscoveredWithErrorException)5 UnableDeleteHostException (com.cloud.resource.UnableDeleteHostException)5 URISyntaxException (java.net.URISyntaxException)5 UnknownHostException (java.net.UnknownHostException)5 ServerApiException (com.cloud.api.ServerApiException)4