Package com.cloud.resource

Examples of com.cloud.resource.ServerResource


                if (_outstandingTaskCount.incrementAndGet() > _agentMgr.getDirectAgentThreadCap()) {
                    s_logger.warn("Task execution for direct attache(" + _id + ") has reached maximum outstanding limit(" + _agentMgr.getDirectAgentThreadCap() + "), bailing out");
                    return;
                }

                ServerResource resource = _resource;

                if (resource != null) {
                    PingCommand cmd = resource.getCurrentStatus(_id);
                    if (cmd == null) {
                        s_logger.warn("Unable to get current status on " + _id + "(" + _name + ")");
                        _mgr.disconnectWithInvestigation(DirectAgentAttache.this, Event.AgentDisconnected);
                        return;
                    }
View Full Code Here


                    s_logger.warn("Task execution for direct attache(" + _id + ") has reached maximum outstanding limit(" + _agentMgr.getDirectAgentThreadCap() + "), bailing out");
                    bailout();
                    return;
                }

                ServerResource resource = _resource;
                Command[] cmds = _req.getCommands();
                boolean stopOnError = _req.stopOnError();

                if (s_logger.isDebugEnabled()) {
                    s_logger.debug(log(seq, "Executing request"));
                }
                ArrayList<Answer> answers = new ArrayList<Answer>(cmds.length);
                for (int i = 0; i < cmds.length; i++) {
                    Answer answer = null;
                    try {
                        if (resource != null) {
                            answer = resource.executeRequest(cmds[i]);
                            if(answer == null) {
                                s_logger.warn("Resource returned null answer!");
                                answer = new Answer(cmds[i], false, "Resource returned null answer");
                            }
                        } else {
View Full Code Here

        params.put("username", "root");
        params.put("password", "password");
        params.put("zone", String.valueOf(host.getDataCenterId()));
        params.put("pod", String.valueOf(host.getPodId()));

        ServerResource resource = null;
        if (host.getHypervisorType() == HypervisorType.XenServer) {
            resource = new XcpOssResource();
            try {
                resource.configure(host.getName(), params);

            } catch (ConfigurationException e) {
                logger.debug("Failed to load resource:" + e.toString());
            }
        } else if (host.getHypervisorType() == HypervisorType.KVM) {
            resource = new LibvirtComputingResource();
            try {
                params.put("public.network.device", "cloudbr0");
                params.put("private.network.device", "cloudbr0");
                resource.configure(host.getName(), params);
            } catch (ConfigurationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else if (host.getHypervisorType() == HypervisorType.VMware) {
            ClusterVO cluster = clusterDao.findById(host.getClusterId());
            String url = clusterDetailsDao.findDetail(cluster.getId(), "url").getValue();
            URI uri;
            try {
                uri = new URI(url);
                String userName = clusterDetailsDao.findDetail(cluster.getId(), "username").getValue();
                String password = clusterDetailsDao.findDetail(cluster.getId(), "password").getValue();
                VmwareServerDiscoverer discover = new VmwareServerDiscoverer();

                Map<? extends ServerResource, Map<String, String>> resources = discover.find(host.getDataCenterId(),
                        host.getPodId(), host.getClusterId(), uri, userName, password, null);
                for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) {
                    resource = entry.getKey();
                }
                if (resource == null) {
                    throw new CloudRuntimeException("can't find resource");
                }
            } catch (DiscoveryException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        hostResourcesMap.put(hostId, resource);
        HostEnvironment env = new HostEnvironment();
        SetupCommand cmd = new SetupCommand(env);
        cmd.setNeedSetup(true);

        resource.executeRequest(cmd);
    }
View Full Code Here

    }

    @Override
    public synchronized Answer send(Long hostId, Command cmd) throws AgentUnavailableException,
            OperationTimedoutException {
        ServerResource resource = hostResourcesMap.get(hostId);
        if (resource == null) {
            loadResource(hostId);
            resource = hostResourcesMap.get(hostId);
        }

        if (resource == null) {
            return null;
        }

        Answer answer = resource.executeRequest(cmd);
        return answer;
    }
View Full Code Here

        params.put("username", "root");
        params.put("password", "password");
        params.put("zone", String.valueOf(host.getDataCenterId()));
        params.put("pod", String.valueOf(host.getPodId()));
       
        ServerResource resource = null;
        if (host.getHypervisorType() == HypervisorType.XenServer) {
             resource = new XcpOssResource();
        }
       
        try {
            resource.configure(host.getName(), params);
            hostResourcesMap.put(hostId, resource);
        } catch (ConfigurationException e) {
            logger.debug("Failed to load resource:" + e.toString());
        }
        HostEnvironment env = new HostEnvironment();
        SetupCommand cmd = new SetupCommand(env);
        cmd.setNeedSetup(true);
       
        resource.executeRequest(cmd);
    }
View Full Code Here

        resource.executeRequest(cmd);
    }

    @Override
    public synchronized Answer send(Long hostId, Command cmd) throws AgentUnavailableException, OperationTimedoutException {
        ServerResource resource = hostResourcesMap.get(hostId);
        if (resource == null) {
            loadResource(hostId);
            resource = hostResourcesMap.get(hostId);
        }
       
        if (resource == null) {
            return null;
        }
       
        Answer answer = resource.executeRequest(cmd);
        return answer;
    }
View Full Code Here

        }
    }

    private ServerResource loadResourcesWithoutHypervisor(HostVO host){
        String resourceName = host.getResource();
        ServerResource resource = null;
        try {
            Class<?> clazz = Class.forName(resourceName);
            Constructor constructor = clazz.getConstructor();
            resource = (ServerResource) constructor.newInstance();
        } catch (ClassNotFoundException e) {
            s_logger.warn("Unable to find class " + host.getResource(), e);
        } catch (InstantiationException e) {
            s_logger.warn("Unablet to instantiate class " + host.getResource(), e);
        } catch (IllegalAccessException e) {
            s_logger.warn("Illegal access " + host.getResource(), e);
        } catch (SecurityException e) {
            s_logger.warn("Security error on " + host.getResource(), e);
        } catch (NoSuchMethodException e) {
            s_logger.warn("NoSuchMethodException error on " + host.getResource(), e);
        } catch (IllegalArgumentException e) {
            s_logger.warn("IllegalArgumentException error on " + host.getResource(), e);
        } catch (InvocationTargetException e) {
            s_logger.warn("InvocationTargetException error on " + host.getResource(), e);
        }

        if(resource != null){
            _hostDao.loadDetails(host);

            HashMap<String, Object> params = new HashMap<String, Object>(host.getDetails().size() + 5);
            params.putAll(host.getDetails());

            params.put("guid", host.getGuid());
            params.put("zone", Long.toString(host.getDataCenterId()));
            if (host.getPodId() != null) {
                params.put("pod", Long.toString(host.getPodId()));
            }
            if (host.getClusterId() != null) {
                params.put("cluster", Long.toString(host.getClusterId()));
                String guid = null;
                ClusterVO cluster = _clusterDao.findById(host.getClusterId());
                if (cluster.getGuid() == null) {
                    guid = host.getDetail("pool");
                } else {
                    guid = cluster.getGuid();
                }
                if (guid != null && !guid.isEmpty()) {
                    params.put("pool", guid);
                }
            }

            params.put("ipaddress", host.getPrivateIpAddress());
            params.put("secondary.storage.vm", "false");
            params.put("max.template.iso.size", _configDao.getValue(Config.MaxTemplateAndIsoSize.toString()));
            params.put("migratewait", _configDao.getValue(Config.MigrateWait.toString()));

            try {
                resource.configure(host.getName(), params);
            } catch (ConfigurationException e) {
                s_logger.warn("Unable to configure resource due to " + e.getMessage());
                return null;
            }

            if (!resource.start()) {
                s_logger.warn("Unable to start the resource");
                return null;
            }
        }
        return resource;
View Full Code Here


    @SuppressWarnings("rawtypes")
    protected boolean loadDirectlyConnectedHost(HostVO host, boolean forRebalance) {
        boolean initialized = false;
        ServerResource resource = null;
        try {
            //load the respective discoverer
            Discoverer discoverer = _resourceMgr.getMatchingDiscover(host.getHypervisorType());
            if(discoverer == null){
                s_logger.info("Could not to find a Discoverer to load the resource: "+ host.getId() +" for hypervisor type: "+host.getHypervisorType());
View Full Code Here

    }

    @Override
    @DB
    public BigSwitchVnsDeviceVO addBigSwitchVnsDevice(AddBigSwitchVnsDeviceCmd cmd) {
        ServerResource resource = new BigSwitchVnsResource();
        String deviceName = VnsConstants.BigSwitchVns.getName();
        NetworkDevice networkDevice = NetworkDevice
                .getNetworkDevice(deviceName);
        Long physicalNetworkId = cmd.getPhysicalNetworkId();
        BigSwitchVnsDeviceVO bigswitchVnsDevice = null;

        PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
                .findById(physicalNetworkId);
        if (physicalNetwork == null) {
            throw new InvalidParameterValueException(
                    "Could not find phyical network with ID: "
                            + physicalNetworkId);
        }
        long zoneId = physicalNetwork.getDataCenterId();

        PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao
                .findByServiceProvider(physicalNetwork.getId(),
                        networkDevice.getNetworkServiceProvder());
        if (ntwkSvcProvider == null) {
            throw new CloudRuntimeException("Network Service Provider: "
                    + networkDevice.getNetworkServiceProvder()
                    + " is not enabled in the physical network: "
                    + physicalNetworkId + "to add this device");
        } else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
            throw new CloudRuntimeException("Network Service Provider: "
                    + ntwkSvcProvider.getProviderName()
                    + " is in shutdown state in the physical network: "
                    + physicalNetworkId + "to add this device");
        }

        if (_bigswitchVnsDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
            throw new CloudRuntimeException(
                    "A BigSwitch controller device is already configured on this physical network");
        }

        Map<String, String> params = new HashMap<String, String>();
        params.put("guid", UUID.randomUUID().toString());
        params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
        params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
        params.put("name", "BigSwitch Controller - " + cmd.getHost());
        params.put("ip", cmd.getHost());
        // FIXME What to do with multiple isolation types
        params.put("transportzoneisotype",
                physicalNetwork.getIsolationMethods().get(0).toLowerCase());

        Map<String, Object> hostdetails = new HashMap<String, Object>();
        hostdetails.putAll(params);

        Transaction txn = Transaction.currentTxn();
        try {
            resource.configure(cmd.getHost(), hostdetails);

            Host host = _resourceMgr.addHost(zoneId, resource,
                    Host.Type.L2Networking, params);
            if (host != null) {
                txn.start();
View Full Code Here

TOP

Related Classes of com.cloud.resource.ServerResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.