Search in sources :

Example 6 with ServerResource

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

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 7 with ServerResource

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

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<>(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 8 with ServerResource

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

the class NiciraNvpElement method addNiciraNvpDevice.

@Override
@DB
public NiciraNvpDeviceVO addNiciraNvpDevice(final AddNiciraNvpDeviceCmd cmd) {
    final ServerResource resource = new NiciraNvpResource();
    final String deviceName = Network.Provider.NiciraNvp.getName();
    final NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    if (networkDevice == null) {
        throw new CloudRuntimeException("No network device found for " + deviceName);
    }
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    final PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    final 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 (niciraNvpDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
        throw new CloudRuntimeException("A NiciraNvp device is already configured on this physical network");
    }
    final Map<String, String> params = new HashMap<>();
    params.put("guid", UUID.randomUUID().toString());
    params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
    params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
    params.put("name", "Nicira Controller - " + cmd.getHost());
    params.put("ip", cmd.getHost());
    params.put("adminuser", cmd.getUsername());
    params.put("adminpass", cmd.getPassword());
    params.put("transportzoneuuid", cmd.getTransportzoneUuid());
    // FIXME What to do with multiple isolation types
    params.put("transportzoneisotype", physicalNetwork.getIsolationMethods().get(0).toLowerCase());
    if (cmd.getL3GatewayServiceUuid() != null) {
        params.put("l3gatewayserviceuuid", cmd.getL3GatewayServiceUuid());
    }
    final Map<String, Object> hostdetails = new HashMap<>();
    hostdetails.putAll(params);
    try {
        resource.configure(cmd.getHost(), hostdetails);
        final Host host = resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params);
        if (host != null) {
            return Transaction.execute(new TransactionCallback<NiciraNvpDeviceVO>() {

                @Override
                public NiciraNvpDeviceVO doInTransaction(final TransactionStatus status) {
                    final NiciraNvpDeviceVO niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
                    niciraNvpDao.persist(niciraNvpDevice);
                    final DetailVO detail = new DetailVO(host.getId(), "niciranvpdeviceid", String.valueOf(niciraNvpDevice.getId()));
                    hostDetailsDao.persist(detail);
                    return niciraNvpDevice;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to add Nicira Nvp Device due to internal error.");
        }
    } catch (final ConfigurationException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) NetworkDevice(com.cloud.network.ExternalNetworkDeviceManager.NetworkDevice) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ServerResource(com.cloud.resource.ServerResource) NiciraNvpResource(com.cloud.network.resource.NiciraNvpResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DB(com.cloud.utils.db.DB)

Example 9 with ServerResource

use of com.cloud.resource.ServerResource in project CloudStack-archive by CloudStack-extras.

the class AgentShell method launchAgentFromClassInfo.

private void launchAgentFromClassInfo(String resourceClassNames) throws ConfigurationException {
    String[] names = resourceClassNames.split("\\|");
    for (String name : names) {
        Class<?> impl;
        try {
            impl = Class.forName(name);
            final Constructor<?> constructor = impl.getDeclaredConstructor();
            constructor.setAccessible(true);
            ServerResource resource = (ServerResource) constructor.newInstance();
            launchAgent(getNextAgentId(), resource);
        } catch (final ClassNotFoundException e) {
            throw new ConfigurationException("Resource class not found: " + name + " due to: " + e.toString());
        } catch (final SecurityException e) {
            throw new ConfigurationException("Security excetion when loading resource: " + name + " due to: " + e.toString());
        } catch (final NoSuchMethodException e) {
            throw new ConfigurationException("Method not found excetion when loading resource: " + name + " due to: " + e.toString());
        } catch (final IllegalArgumentException e) {
            throw new ConfigurationException("Illegal argument excetion when loading resource: " + name + " due to: " + e.toString());
        } catch (final InstantiationException e) {
            throw new ConfigurationException("Instantiation excetion when loading resource: " + name + " due to: " + e.toString());
        } catch (final IllegalAccessException e) {
            throw new ConfigurationException("Illegal access exception when loading resource: " + name + " due to: " + e.toString());
        } catch (final InvocationTargetException e) {
            throw new ConfigurationException("Invocation target exception when loading resource: " + name + " due to: " + e.toString());
        }
    }
}
Also used : ServerResource(com.cloud.resource.ServerResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(javax.naming.ConfigurationException)

Example 10 with ServerResource

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

the class AgentShell method launchAgentFromClassInfo.

private void launchAgentFromClassInfo(String resourceClassNames) throws ConfigurationException {
    String[] names = resourceClassNames.split("\\|");
    for (String name : names) {
        Class<?> impl;
        try {
            impl = Class.forName(name);
            final Constructor<?> constructor = impl.getDeclaredConstructor();
            constructor.setAccessible(true);
            ServerResource resource = (ServerResource) constructor.newInstance();
            launchNewAgent(resource);
        } catch (final ClassNotFoundException e) {
            throw new ConfigurationException("Resource class not found: " + name + " due to: " + e.toString());
        } catch (final SecurityException e) {
            throw new ConfigurationException("Security exception when loading resource: " + name + " due to: " + e.toString());
        } catch (final NoSuchMethodException e) {
            throw new ConfigurationException("Method not found exception when loading resource: " + name + " due to: " + e.toString());
        } catch (final IllegalArgumentException e) {
            throw new ConfigurationException("Illegal argument exception when loading resource: " + name + " due to: " + e.toString());
        } catch (final InstantiationException e) {
            throw new ConfigurationException("Instantiation exception when loading resource: " + name + " due to: " + e.toString());
        } catch (final IllegalAccessException e) {
            throw new ConfigurationException("Illegal access exception when loading resource: " + name + " due to: " + e.toString());
        } catch (final InvocationTargetException e) {
            throw new ConfigurationException("Invocation target exception when loading resource: " + name + " due to: " + e.toString());
        }
    }
}
Also used : ServerResource(com.cloud.resource.ServerResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(javax.naming.ConfigurationException)

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