Search in sources :

Example 11 with ServerResource

use of com.cloud.resource.ServerResource in project cloudstack by apache.

the class AgentManagerImpl method loadResourcesWithoutHypervisor.

private ServerResource loadResourcesWithoutHypervisor(final HostVO host) {
    final String resourceName = host.getResource();
    ServerResource resource = null;
    try {
        final Class<?> clazz = Class.forName(resourceName);
        final Constructor<?> constructor = clazz.getConstructor();
        resource = (ServerResource) constructor.newInstance();
    } catch (final ClassNotFoundException e) {
        s_logger.warn("Unable to find class " + host.getResource(), e);
    } catch (final InstantiationException e) {
        s_logger.warn("Unablet to instantiate class " + host.getResource(), e);
    } catch (final IllegalAccessException e) {
        s_logger.warn("Illegal access " + host.getResource(), e);
    } catch (final SecurityException e) {
        s_logger.warn("Security error on " + host.getResource(), e);
    } catch (final NoSuchMethodException e) {
        s_logger.warn("NoSuchMethodException error on " + host.getResource(), e);
    } catch (final IllegalArgumentException e) {
        s_logger.warn("IllegalArgumentException error on " + host.getResource(), e);
    } catch (final InvocationTargetException e) {
        s_logger.warn("InvocationTargetException error on " + host.getResource(), e);
    }
    if (resource != null) {
        _hostDao.loadDetails(host);
        final 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;
            final 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");
        try {
            resource.configure(host.getName(), params);
        } catch (final 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;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ServerResource(com.cloud.resource.ServerResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(javax.naming.ConfigurationException)

Example 12 with ServerResource

use of com.cloud.resource.ServerResource in project cloudstack by apache.

the class AgentManagerImpl method loadDirectlyConnectedHost.

protected boolean loadDirectlyConnectedHost(final HostVO host, final boolean forRebalance) {
    boolean initialized = false;
    ServerResource resource = null;
    try {
        // load the respective discoverer
        final 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());
            resource = loadResourcesWithoutHypervisor(host);
        } else {
            resource = discoverer.reloadResource(host);
        }
        if (resource == null) {
            s_logger.warn("Unable to load the resource: " + host.getId());
            return false;
        }
        initialized = true;
    } finally {
        if (!initialized) {
            if (host != null) {
                agentStatusTransitTo(host, Event.AgentDisconnected, _nodeId);
            }
        }
    }
    if (forRebalance) {
        tapLoadingAgents(host.getId(), TapAgentsAction.Add);
        final Host h = _resourceMgr.createHostAndAgent(host.getId(), resource, host.getDetails(), false, null, true);
        tapLoadingAgents(host.getId(), TapAgentsAction.Del);
        return h == null ? false : true;
    } else {
        _executor.execute(new SimulateStartTask(host.getId(), resource, host.getDetails()));
        return true;
    }
}
Also used : ServerResource(com.cloud.resource.ServerResource) Discoverer(com.cloud.resource.Discoverer) Host(com.cloud.host.Host)

Example 13 with ServerResource

use of com.cloud.resource.ServerResource in project cosmic by MissionCriticalCloud.

the class AgentShell method loadServerResource.

private ServerResource loadServerResource(final String resourceClassName) throws ConfigurationException {
    logger.debug("Loading agent resource from class name {}", resourceClassName);
    final String[] names = resourceClassName.split("\\|");
    for (final String name : names) {
        final Class<?> impl;
        try {
            impl = Class.forName(name);
            final Constructor<?> constructor = impl.getDeclaredConstructor();
            constructor.setAccessible(true);
            return (ServerResource) constructor.newInstance();
        } catch (final ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalArgumentException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
            throw new ConfigurationException("Failed to launch agent due to " + e.getClass().getSimpleName() + ": " + e.getMessage());
        }
    }
    throw new ConfigurationException("Could not find server resource class to load in: " + resourceClassName);
}
Also used : ServerResource(com.cloud.resource.ServerResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(javax.naming.ConfigurationException)

Example 14 with ServerResource

use of com.cloud.resource.ServerResource in project cosmic by MissionCriticalCloud.

the class AgentShell method launchAgent.

private void launchAgent() throws ConfigurationException {
    final String resourceClassNames = agentProperties.getResource();
    logger.debug("Launching agent with resource {}", resourceClassNames);
    if (resourceClassNames != null) {
        final ServerResource serverResource = loadServerResource(agentProperties.getResource());
        configureServerResource(serverResource);
        agent = new Agent(agentProperties, backOff, serverResource);
        agent.start();
    } else {
        throw new ConfigurationException("Cannot launch agent without a agent resource class");
    }
}
Also used : ConfigurationException(javax.naming.ConfigurationException) ServerResource(com.cloud.resource.ServerResource)

Example 15 with ServerResource

use of com.cloud.resource.ServerResource in project cloudstack by apache.

the class CiscoVnmcElement method addCiscoVnmcResource.

@Override
public CiscoVnmcController addCiscoVnmcResource(AddCiscoVnmcResourceCmd cmd) {
    final String deviceName = Provider.CiscoVnmc.getName();
    NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    CiscoVnmcController ciscoVnmcResource = null;
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    long zoneId = physicalNetwork.getDataCenterId();
    final 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 (_ciscoVnmcDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
        throw new CloudRuntimeException("A Cisco Vnmc 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", "Cisco VNMC Controller - " + cmd.getHost());
    params.put("ip", cmd.getHost());
    params.put("username", cmd.getUsername());
    params.put("password", cmd.getPassword());
    Map<String, Object> hostdetails = new HashMap<String, Object>();
    hostdetails.putAll(params);
    ServerResource resource = new CiscoVnmcResource();
    try {
        resource.configure(cmd.getHost(), hostdetails);
        final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.ExternalFirewall, params);
        if (host != null) {
            return Transaction.execute(new TransactionCallback<CiscoVnmcController>() {

                @Override
                public CiscoVnmcController doInTransaction(TransactionStatus status) {
                    CiscoVnmcController ciscoVnmcResource = new CiscoVnmcControllerVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
                    _ciscoVnmcDao.persist((CiscoVnmcControllerVO) ciscoVnmcResource);
                    DetailVO detail = new DetailVO(host.getId(), "deviceid", String.valueOf(ciscoVnmcResource.getId()));
                    _hostDetailsDao.persist(detail);
                    return ciscoVnmcResource;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to add Cisco Vnmc device due to internal error.");
        }
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) NetworkDevice(org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice) ServerResource(com.cloud.resource.ServerResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) ConfigurationException(javax.naming.ConfigurationException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CiscoVnmcResource(com.cloud.network.resource.CiscoVnmcResource) CiscoVnmcController(com.cloud.network.cisco.CiscoVnmcController) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO)

Aggregations

ServerResource (com.cloud.resource.ServerResource)23 ConfigurationException (javax.naming.ConfigurationException)17 HashMap (java.util.HashMap)15 Host (com.cloud.host.Host)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)9 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)9 DB (com.cloud.utils.db.DB)8 TransactionStatus (com.cloud.utils.db.TransactionStatus)7 Map (java.util.Map)7 HostVO (com.cloud.host.HostVO)6 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 DetailVO (com.cloud.host.DetailVO)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 NetworkDevice (org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice)5 URI (java.net.URI)4 ClusterVO (com.cloud.dc.ClusterVO)3 DataCenterVO (com.cloud.dc.DataCenterVO)3 BaremetalPxeVO (com.cloud.baremetal.database.BaremetalPxeVO)2 NetScalerControlCenterVO (com.cloud.network.NetScalerControlCenterVO)2