Search in sources :

Example 1 with AgentRoutingResource

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

the class MockAgentManagerImpl method createServerResources.

@Override
@DB
public Map<AgentResourceBase, Map<String, String>> createServerResources(Map<String, Object> params) {
    Map<String, String> args = new HashMap<String, String>();
    Map<AgentResourceBase, Map<String, String>> newResources = new HashMap<AgentResourceBase, Map<String, String>>();
    AgentResourceBase agentResource;
    long cpuCore = Long.parseLong((String) params.get("cpucore"));
    long cpuSpeed = Long.parseLong((String) params.get("cpuspeed"));
    long memory = Long.parseLong((String) params.get("memory"));
    long localStorageSize = Long.parseLong((String) params.get("localstorage"));
    synchronized (this) {
        long dataCenterId = Long.parseLong((String) params.get("zone"));
        long podId = Long.parseLong((String) params.get("pod"));
        long clusterId = Long.parseLong((String) params.get("cluster"));
        long cidrSize = getPodCidr(podId, dataCenterId).second();
        int agentId = getNextAgentId(cidrSize);
        String ipAddress = getIpAddress(agentId, dataCenterId, podId);
        String macAddress = getMacAddress(dataCenterId, podId, clusterId, agentId);
        MockHostVO mockHost = new MockHostVO();
        mockHost.setDataCenterId(dataCenterId);
        mockHost.setPodId(podId);
        mockHost.setClusterId(clusterId);
        mockHost.setCapabilities("hvm");
        mockHost.setCpuCount(cpuCore);
        mockHost.setCpuSpeed(cpuSpeed);
        mockHost.setMemorySize(memory);
        String guid = UUID.randomUUID().toString();
        mockHost.setGuid(guid);
        mockHost.setName("SimulatedAgent." + guid);
        mockHost.setPrivateIpAddress(ipAddress);
        mockHost.setPublicIpAddress(ipAddress);
        mockHost.setStorageIpAddress(ipAddress);
        mockHost.setPrivateMacAddress(macAddress);
        mockHost.setPublicMacAddress(macAddress);
        mockHost.setStorageMacAddress(macAddress);
        mockHost.setVersion(this.getClass().getPackage().getImplementationVersion());
        mockHost.setResource("com.cloud.agent.AgentRoutingResource");
        mockHost = _mockHostDao.persist(mockHost);
        _storageMgr.getLocalStorage(guid, localStorageSize);
        agentResource = new AgentRoutingResource();
        if (agentResource != null) {
            try {
                params.put("guid", mockHost.getGuid());
                agentResource.start();
                agentResource.configure(mockHost.getName(), params);
                newResources.put(agentResource, args);
            } catch (ConfigurationException e) {
                s_logger.error("error while configuring server resource" + e.getMessage());
            }
        }
    }
    return newResources;
}
Also used : AgentResourceBase(com.cloud.resource.AgentResourceBase) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConfigurationException(javax.naming.ConfigurationException) AgentRoutingResource(com.cloud.resource.AgentRoutingResource) MockHostVO(com.cloud.simulator.MockHostVO) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DB(com.cloud.utils.db.DB)

Example 2 with AgentRoutingResource

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

the class MockAgentManagerImpl method createServerResources.

@Override
@DB
public Map<AgentResourceBase, Map<String, String>> createServerResources(Map<String, Object> params) {
    Map<String, String> args = new HashMap<String, String>();
    Map<AgentResourceBase, Map<String, String>> newResources = new HashMap<AgentResourceBase, Map<String, String>>();
    AgentResourceBase agentResource;
    long cpuCore = Long.parseLong((String) params.get("cpucore"));
    long cpuSpeed = Long.parseLong((String) params.get("cpuspeed"));
    long memory = Long.parseLong((String) params.get("memory"));
    long localStorageSize = Long.parseLong((String) params.get("localstorage"));
    synchronized (this) {
        long dataCenterId = Long.parseLong((String) params.get("zone"));
        long podId = Long.parseLong((String) params.get("pod"));
        long clusterId = Long.parseLong((String) params.get("cluster"));
        long cidrSize = getPodCidr(podId, dataCenterId).second();
        int agentId = getNextAgentId(cidrSize);
        String ipAddress = getIpAddress(agentId, dataCenterId, podId);
        String macAddress = getMacAddress(dataCenterId, podId, clusterId, agentId);
        MockHostVO mockHost = new MockHostVO();
        mockHost.setDataCenterId(dataCenterId);
        mockHost.setPodId(podId);
        mockHost.setClusterId(clusterId);
        mockHost.setCapabilities("hvm");
        mockHost.setCpuCount(cpuCore);
        mockHost.setCpuSpeed(cpuSpeed);
        mockHost.setMemorySize(memory);
        String guid = UUID.randomUUID().toString();
        mockHost.setGuid(guid);
        mockHost.setName("SimulatedAgent." + guid);
        mockHost.setPrivateIpAddress(ipAddress);
        mockHost.setPublicIpAddress(ipAddress);
        mockHost.setStorageIpAddress(ipAddress);
        mockHost.setPrivateMacAddress(macAddress);
        mockHost.setPublicMacAddress(macAddress);
        mockHost.setStorageMacAddress(macAddress);
        mockHost.setVersion(this.getClass().getPackage().getImplementationVersion());
        mockHost.setResource("com.cloud.agent.AgentRoutingResource");
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        try {
            txn.start();
            mockHost = _mockHostDao.persist(mockHost);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            s_logger.error("Error while configuring mock agent " + ex.getMessage());
            throw new CloudRuntimeException("Error configuring agent", ex);
        } finally {
            txn.close();
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }
        _storageMgr.getLocalStorage(guid, localStorageSize);
        agentResource = new AgentRoutingResource();
        if (agentResource != null) {
            try {
                params.put("guid", mockHost.getGuid());
                agentResource.start();
                agentResource.configure(mockHost.getName(), params);
                newResources.put(agentResource, args);
            } catch (ConfigurationException e) {
                s_logger.error("error while configuring server resource" + e.getMessage());
            }
        }
    }
    return newResources;
}
Also used : AgentResourceBase(com.cloud.resource.AgentResourceBase) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AgentRoutingResource(com.cloud.resource.AgentRoutingResource) MockHostVO(com.cloud.simulator.MockHostVO) DiscoveryException(com.cloud.exception.DiscoveryException) PatternSyntaxException(java.util.regex.PatternSyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DB(com.cloud.utils.db.DB)

Aggregations

AgentResourceBase (com.cloud.resource.AgentResourceBase)2 AgentRoutingResource (com.cloud.resource.AgentRoutingResource)2 MockHostVO (com.cloud.simulator.MockHostVO)2 DB (com.cloud.utils.db.DB)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConfigurationException (javax.naming.ConfigurationException)2 DiscoveryException (com.cloud.exception.DiscoveryException)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1