Search in sources :

Example 16 with ServerResource

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

the class SecondaryStorageDiscoverer method createDummySecondaryStorageResource.

protected Map<ServerResource, Map<String, String>> createDummySecondaryStorageResource(long dcId, Long podId, URI uri) {
    Map<ServerResource, Map<String, String>> srs = new HashMap<ServerResource, Map<String, String>>();
    DummySecondaryStorageResource storage = new DummySecondaryStorageResource(_useServiceVM);
    storage = ComponentContext.inject(storage);
    Map<String, String> details = new HashMap<String, String>();
    details.put("mount.path", uri.toString());
    details.put("orig.url", uri.toString());
    Map<String, Object> params = new HashMap<String, Object>();
    params.putAll(details);
    params.put("zone", Long.toString(dcId));
    if (podId != null) {
        params.put("pod", podId.toString());
    }
    params.put("guid", uri.toString());
    try {
        storage.configure("Storage", params);
    } catch (ConfigurationException e) {
        s_logger.warn("Unable to configure the storage ", e);
        return null;
    }
    srs.put(storage, details);
    return srs;
}
Also used : DummySecondaryStorageResource(com.cloud.storage.resource.DummySecondaryStorageResource) HashMap(java.util.HashMap) ConfigurationException(javax.naming.ConfigurationException) ServerResource(com.cloud.resource.ServerResource) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with ServerResource

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

the class BigSwitchBcfElement method addBigSwitchBcfDevice.

@Override
@DB
public BigSwitchBcfDeviceVO addBigSwitchBcfDevice(AddBigSwitchBcfDeviceCmd cmd) {
    BigSwitchBcfDeviceVO newBcfDevice;
    bcfUtilsInit();
    ServerResource resource = new BigSwitchBcfResource();
    final String deviceName = BcfConstants.BIG_SWITCH_BCF.getName();
    NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    final String hostname = cmd.getHost();
    final String username = cmd.getUsername();
    final String password = cmd.getPassword();
    final Boolean nat = cmd.getNat();
    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");
    }
    ntwkSvcProvider.setFirewallServiceProvided(true);
    ntwkSvcProvider.setGatewayServiceProvided(true);
    ntwkSvcProvider.setNetworkAclServiceProvided(true);
    ntwkSvcProvider.setSourcenatServiceProvided(true);
    ntwkSvcProvider.setStaticnatServiceProvided(true);
    if (_bigswitchBcfDao.listByPhysicalNetwork(physicalNetworkId).size() > 1) {
        throw new CloudRuntimeException("At most two BCF controllers can be configured");
    }
    DataCenterVO zone = _zoneDao.findById(physicalNetwork.getDataCenterId());
    String zoneName;
    if (zone != null) {
        zoneName = zone.getName();
    } else {
        zoneName = String.valueOf(zoneId);
    }
    Boolean natNow = _bcfUtils.isNatEnabled();
    if (!nat && natNow) {
        throw new CloudRuntimeException("NAT is enabled in existing controller. Enable NAT for new controller or remove existing controller first.");
    } else if (nat && !natNow) {
        throw new CloudRuntimeException("NAT is disabled in existing controller. Disable NAT for new controller or remove existing controller first.");
    }
    Map<String, String> params = new HashMap<String, String>();
    params.put("guid", UUID.randomUUID().toString());
    params.put("zoneId", zoneName);
    params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
    params.put("name", "BigSwitch Controller - " + cmd.getHost());
    params.put("hostname", cmd.getHost());
    params.put("username", username);
    params.put("password", password);
    params.put("nat", nat.toString());
    // 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);
    try {
        resource.configure(cmd.getHost(), hostdetails);
        // store current topology in bcf resource
        TopologyData topo = _bcfUtils.getTopology(physicalNetwork.getId());
        ((BigSwitchBcfResource) resource).setTopology(topo);
        final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params);
        if (host != null) {
            newBcfDevice = Transaction.execute(new TransactionCallback<BigSwitchBcfDeviceVO>() {

                @Override
                public BigSwitchBcfDeviceVO doInTransaction(TransactionStatus status) {
                    BigSwitchBcfDeviceVO bigswitchBcfDevice = new BigSwitchBcfDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName, hostname, username, password, nat, BigSwitchBcfApi.HASH_IGNORE);
                    _bigswitchBcfDao.persist(bigswitchBcfDevice);
                    DetailVO detail = new DetailVO(host.getId(), "bigswitchbcfdeviceid", String.valueOf(bigswitchBcfDevice.getId()));
                    _hostDetailsDao.persist(detail);
                    return bigswitchBcfDevice;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to add BigSwitch BCF Controller Device due to internal error.");
        }
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
    // initial topology sync to newly added BCF controller
    HostVO bigswitchBcfHost = _hostDao.findById(newBcfDevice.getHostId());
    _bcfUtils.syncTopologyToBcfHost(bigswitchBcfHost, nat);
    return newBcfDevice;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) 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) HostVO(com.cloud.host.HostVO) TransactionCallback(com.cloud.utils.db.TransactionCallback) BigSwitchBcfResource(com.cloud.network.resource.BigSwitchBcfResource) 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) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) TopologyData(com.cloud.network.bigswitch.TopologyData) BigSwitchBcfDeviceVO(com.cloud.network.BigSwitchBcfDeviceVO) DB(com.cloud.utils.db.DB)

Example 18 with ServerResource

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

the class OpenDaylightControllerResourceManagerImpl method addController.

@Override
public OpenDaylightControllerVO addController(AddOpenDaylightControllerCmd cmd) {
    ServerResource odlController = new OpenDaylightControllerResource();
    final String deviceName = NetworkDevice.OpenDaylightController.getName();
    NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    if (networkDevice == null) {
        throw new CloudRuntimeException("No network device found for name " + deviceName);
    }
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    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");
    }
    final Map<String, String> hostParams = new HashMap<String, String>();
    hostParams.put("guid", UUID.randomUUID().toString());
    hostParams.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
    hostParams.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
    hostParams.put("name", "ODL Controller - " + hostParams.get("guid"));
    hostParams.put("url", cmd.getUrl());
    hostParams.put("username", cmd.getUsername());
    hostParams.put("password", cmd.getPassword());
    Map<String, Object> hostdetails = new HashMap<String, Object>();
    hostdetails.putAll(hostParams);
    try {
        odlController.configure(hostParams.get("name"), hostdetails);
        final Host host = resourceManager.addHost(zoneId, odlController, Host.Type.L2Networking, hostParams);
        if (host != null) {
            return Transaction.execute(new TransactionCallback<OpenDaylightControllerVO>() {

                @Override
                public OpenDaylightControllerVO doInTransaction(TransactionStatus status) {
                    OpenDaylightControllerVO controller = new OpenDaylightControllerVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), hostParams.get("name"));
                    openDaylightControllerMappingDao.persist(controller);
                    return controller;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to create host object for ODL Controller");
        }
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException("Failed to add ODL Controller as a resource", e);
    }
}
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) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

Example 19 with ServerResource

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

the class DirectAgentManagerSimpleImpl method loadResource.

protected void loadResource(Long hostId) {
    HostVO host = hostDao.findById(hostId);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("guid", host.getGuid());
    params.put("ipaddress", host.getPrivateIpAddress());
    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);
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) HashMap(java.util.HashMap) ServerResource(com.cloud.resource.ServerResource) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) VmwareServerDiscoverer(com.cloud.hypervisor.vmware.VmwareServerDiscoverer) HostEnvironment(com.cloud.host.HostEnvironment) SetupCommand(com.cloud.agent.api.SetupCommand) HostVO(com.cloud.host.HostVO) XcpOssResource(com.cloud.hypervisor.xenserver.resource.XcpOssResource) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) LibvirtComputingResource(com.cloud.hypervisor.kvm.resource.LibvirtComputingResource) HashMap(java.util.HashMap) Map(java.util.Map) DiscoveryException(com.cloud.exception.DiscoveryException)

Example 20 with ServerResource

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

the class DirectAgentManagerSimpleImpl method send.

@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;
}
Also used : Answer(com.cloud.agent.api.Answer) ServerResource(com.cloud.resource.ServerResource)

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