Search in sources :

Example 1 with ServerResource

use of com.cloud.common.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 = this._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, this._nodeId);
            }
        }
    }
    if (forRebalance) {
        tapLoadingAgents(host.getId(), TapAgentsAction.Add);
        final Host h = this._resourceMgr.createHostAndAgent(host.getId(), resource, host.getDetails(), false, null, true);
        tapLoadingAgents(host.getId(), TapAgentsAction.Del);
        return h == null ? false : true;
    } else {
        this._executor.execute(new SimulateStartTask(host.getId(), resource, host.getDetails()));
        return true;
    }
}
Also used : ServerResource(com.cloud.common.resource.ServerResource) Discoverer(com.cloud.resource.Discoverer) Host(com.cloud.legacymodel.dc.Host)

Example 2 with ServerResource

use of com.cloud.common.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) {
        this._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 = this._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.common.resource.ServerResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(javax.naming.ConfigurationException)

Example 3 with ServerResource

use of com.cloud.common.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 = this.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 = this.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 (this.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 = this.resourceMgr.addHost(zoneId, resource, HostType.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);
                    NiciraNvpElement.this.niciraNvpDao.persist(niciraNvpDevice);
                    final DetailVO detail = new DetailVO(host.getId(), "niciranvpdeviceid", String.valueOf(niciraNvpDevice.getId()));
                    NiciraNvpElement.this.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.common.resource.ServerResource) NiciraNvpResource(com.cloud.network.resource.NiciraNvpResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.legacymodel.dc.Host) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DB(com.cloud.utils.db.DB)

Example 4 with ServerResource

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

the class DiscovererBase method getResource.

protected ServerResource getResource(final String resourceName) {
    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 " + resourceName, e);
    } catch (final InstantiationException e) {
        s_logger.warn("Unablet to instantiate class " + resourceName, e);
    } catch (final IllegalAccessException e) {
        s_logger.warn("Illegal access " + resourceName, e);
    } catch (final SecurityException e) {
        s_logger.warn("Security error on " + resourceName, e);
    } catch (final NoSuchMethodException e) {
        s_logger.warn("NoSuchMethodException error on " + resourceName, e);
    } catch (final IllegalArgumentException e) {
        s_logger.warn("IllegalArgumentException error on " + resourceName, e);
    } catch (final InvocationTargetException e) {
        s_logger.warn("InvocationTargetException error on " + resourceName, e);
    }
    return resource;
}
Also used : Constructor(java.lang.reflect.Constructor) ServerResource(com.cloud.common.resource.ServerResource) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with ServerResource

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

the class ResourceManagerImpl method processResourceEvent.

protected void processResourceEvent(final Integer event, final Object... params) {
    final List<ResourceListener> lst = this._lifeCycleListeners.get(event);
    if (lst == null || lst.size() == 0) {
        return;
    }
    String eventName;
    for (final ResourceListener l : lst) {
        if (event.equals(ResourceListener.EVENT_DISCOVER_BEFORE)) {
            l.processDiscoverEventBefore((Long) params[0], (Long) params[1], (Long) params[2], (URI) params[3], (String) params[4], (String) params[5], (List<String>) params[6]);
            eventName = "EVENT_DISCOVER_BEFORE";
        } else if (event.equals(ResourceListener.EVENT_DISCOVER_AFTER)) {
            l.processDiscoverEventAfter((Map<? extends ServerResource, Map<String, String>>) params[0]);
            eventName = "EVENT_DISCOVER_AFTER";
        } else if (event.equals(ResourceListener.EVENT_DELETE_HOST_BEFORE)) {
            l.processDeleteHostEventBefore((HostVO) params[0]);
            eventName = "EVENT_DELETE_HOST_BEFORE";
        } else if (event.equals(ResourceListener.EVENT_DELETE_HOST_AFTER)) {
            l.processDeletHostEventAfter((HostVO) params[0]);
            eventName = "EVENT_DELETE_HOST_AFTER";
        } else if (event.equals(ResourceListener.EVENT_CANCEL_MAINTENANCE_BEFORE)) {
            l.processCancelMaintenaceEventBefore((Long) params[0]);
            eventName = "EVENT_CANCEL_MAINTENANCE_BEFORE";
        } else if (event.equals(ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER)) {
            l.processCancelMaintenaceEventAfter((Long) params[0]);
            eventName = "EVENT_CANCEL_MAINTENANCE_AFTER";
        } else if (event.equals(ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE)) {
            l.processPrepareMaintenaceEventBefore((Long) params[0]);
            eventName = "EVENT_PREPARE_MAINTENANCE_BEFORE";
        } else if (event.equals(ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER)) {
            l.processPrepareMaintenaceEventAfter((Long) params[0]);
            eventName = "EVENT_PREPARE_MAINTENANCE_AFTER";
        } else {
            throw new CloudRuntimeException("Unknown resource event:" + event);
        }
        s_logger.debug("Sent resource event " + eventName + " to listener " + l.getClass().getSimpleName());
    }
}
Also used : ResourceListener(com.cloud.common.request.ResourceListener) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ServerResource(com.cloud.common.resource.ServerResource) Map(java.util.Map) HashMap(java.util.HashMap) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO)

Aggregations

ServerResource (com.cloud.common.resource.ServerResource)8 HashMap (java.util.HashMap)5 ConfigurationException (javax.naming.ConfigurationException)5 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)4 HostVO (com.cloud.host.HostVO)3 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)3 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)3 Map (java.util.Map)3 ClusterVO (com.cloud.dc.ClusterVO)2 DataCenterVO (com.cloud.dc.DataCenterVO)2 HostPodVO (com.cloud.dc.HostPodVO)2 Host (com.cloud.legacymodel.dc.Host)2 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)2 DiscoveryException (com.cloud.legacymodel.exceptions.DiscoveryException)2 NoTransitionException (com.cloud.legacymodel.exceptions.NoTransitionException)2 ResourceInUseException (com.cloud.legacymodel.exceptions.ResourceInUseException)2 UnableDeleteHostException (com.cloud.legacymodel.exceptions.UnableDeleteHostException)2 Account (com.cloud.legacymodel.user.Account)2 DB (com.cloud.utils.db.DB)2 SshException (com.cloud.utils.ssh.SshException)2