Search in sources :

Example 11 with StartupStorageCommand

use of com.cloud.agent.api.StartupStorageCommand in project cloudstack by apache.

the class VmwareResource method initializeLocalStorage.

private List<StartupStorageCommand> initializeLocalStorage() {
    List<StartupStorageCommand> storageCmds = new ArrayList<StartupStorageCommand>();
    VmwareContext context = getServiceContext();
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(context);
        if (hyperHost instanceof HostMO) {
            HostMO hostMo = (HostMO) hyperHost;
            List<Pair<ManagedObjectReference, String>> dsList = hostMo.getLocalDatastoreOnHost();
            for (Pair<ManagedObjectReference, String> dsPair : dsList) {
                DatastoreMO dsMo = new DatastoreMO(context, dsPair.first());
                String poolUuid = dsMo.getCustomFieldValue(CustomFieldConstants.CLOUD_UUID);
                if (poolUuid == null || poolUuid.isEmpty()) {
                    poolUuid = UUID.randomUUID().toString();
                    dsMo.setCustomFieldValue(CustomFieldConstants.CLOUD_UUID, poolUuid);
                }
                DatastoreSummary dsSummary = dsMo.getSummary();
                String address = hostMo.getHostName();
                StoragePoolInfo pInfo = new StoragePoolInfo(poolUuid, address, dsMo.getMor().getValue(), "", StoragePoolType.VMFS, dsSummary.getCapacity(), dsSummary.getFreeSpace());
                StartupStorageCommand cmd = new StartupStorageCommand();
                cmd.setName(poolUuid);
                cmd.setPoolInfo(pInfo);
                // give storage host the same UUID as the local storage pool itself
                cmd.setGuid(poolUuid);
                cmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
                cmd.setDataCenter(_dcId);
                cmd.setPod(_pod);
                cmd.setCluster(_cluster);
                s_logger.info("Add local storage startup command: " + _gson.toJson(cmd));
                storageCmds.add(cmd);
            }
        } else {
            s_logger.info("Cluster host does not support local storage, skip it");
        }
    } catch (Exception e) {
        String msg = "initializing local storage failed due to : " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg);
        invalidateServiceContext();
        throw new CloudRuntimeException(msg);
    }
    return storageCmds;
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) ArrayList(java.util.ArrayList) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) DatastoreSummary(com.vmware.vim25.DatastoreSummary) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) Pair(com.cloud.utils.Pair) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 12 with StartupStorageCommand

use of com.cloud.agent.api.StartupStorageCommand in project cloudstack by apache.

the class AgentRoutingResource method initializeLocalSR.

private StartupStorageCommand initializeLocalSR() {
    Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
    StoragePoolInfo poolInfo = _simMgr.getLocalStorage(hostGuid);
    StartupStorageCommand cmd = new StartupStorageCommand(poolInfo.getHostPath(), poolInfo.getPoolType(), poolInfo.getCapacityBytes(), tInfo);
    cmd.setPoolInfo(poolInfo);
    cmd.setGuid(agentHost.getGuid());
    cmd.setResourceType(StorageResourceType.STORAGE_POOL);
    return cmd;
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) HashMap(java.util.HashMap) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo)

Example 13 with StartupStorageCommand

use of com.cloud.agent.api.StartupStorageCommand in project cloudstack by apache.

the class LocalStoragePoolListener method processConnect.

@Override
@DB
public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
    if (!(cmd instanceof StartupStorageCommand)) {
        return;
    }
    StartupStorageCommand ssCmd = (StartupStorageCommand) cmd;
    if (ssCmd.getResourceType() != Storage.StorageResourceType.STORAGE_POOL) {
        return;
    }
    StoragePoolInfo pInfo = ssCmd.getPoolInfo();
    if (pInfo == null) {
        return;
    }
    this._storageMgr.createLocalStorage(host, pInfo);
}
Also used : StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) DB(com.cloud.utils.db.DB)

Example 14 with StartupStorageCommand

use of com.cloud.agent.api.StartupStorageCommand in project CloudStack-archive by CloudStack-extras.

the class FakeComputingResource method initialize.

@Override
public StartupCommand[] initialize() {
    Map<String, VmState> changes = null;
    final List<Object> info = getHostInfo();
    final StartupRoutingCommand cmd = new StartupRoutingCommand((Integer) info.get(0), (Long) info.get(1), (Long) info.get(2), (Long) info.get(4), (String) info.get(3), HypervisorType.KVM, RouterPrivateIpStrategy.HostLocal, changes);
    fillNetworkInformation(cmd);
    cmd.getHostDetails().putAll(getVersionStrings());
    cmd.setCluster(getConfiguredProperty("cluster", "1"));
    StoragePoolInfo pi = initializeLocalStorage();
    StartupStorageCommand sscmd = new StartupStorageCommand();
    sscmd.setPoolInfo(pi);
    sscmd.setGuid(pi.getUuid());
    sscmd.setDataCenter((String) _params.get("zone"));
    sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
    return new StartupCommand[] { cmd, sscmd };
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) VmState(com.cloud.agent.api.StartupRoutingCommand.VmState) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 15 with StartupStorageCommand

use of com.cloud.agent.api.StartupStorageCommand in project CloudStack-archive by CloudStack-extras.

the class AgentRoutingResource method initialize.

@Override
public StartupCommand[] initialize() {
    synchronized (_vms) {
        _vms.clear();
    }
    Map<String, State> changes = _simMgr.getVmStates(this.hostGuid);
    Map<String, MockVMVO> vmsMaps = _simMgr.getVms(this.hostGuid);
    totalCpu = agentHost.getCpuCount() * agentHost.getCpuSpeed();
    totalMem = agentHost.getMemorySize();
    for (Map.Entry<String, MockVMVO> entry : vmsMaps.entrySet()) {
        MockVMVO vm = entry.getValue();
        usedCpu += vm.getCpu();
        usedMem += vm.getMemory();
        _runningVms.put(entry.getKey(), new Pair<Long, Long>(Long.valueOf(vm.getCpu()), vm.getMemory()));
    }
    List<Object> info = getHostInfo();
    StartupRoutingCommand cmd = new StartupRoutingCommand((Integer) info.get(0), (Long) info.get(1), (Long) info.get(2), (Long) info.get(4), (String) info.get(3), HypervisorType.Simulator, RouterPrivateIpStrategy.HostLocal);
    cmd.setStateChanges(changes);
    Map<String, String> hostDetails = new HashMap<String, String>();
    hostDetails.put(RouterPrivateIpStrategy.class.getCanonicalName(), RouterPrivateIpStrategy.DcGlobal.toString());
    cmd.setHostDetails(hostDetails);
    cmd.setAgentTag("agent-simulator");
    cmd.setPrivateIpAddress(agentHost.getPrivateIpAddress());
    cmd.setPrivateNetmask(agentHost.getPrivateNetMask());
    cmd.setPrivateMacAddress(agentHost.getPrivateMacAddress());
    cmd.setStorageIpAddress(agentHost.getStorageIpAddress());
    cmd.setStorageNetmask(agentHost.getStorageNetMask());
    cmd.setStorageMacAddress(agentHost.getStorageMacAddress());
    cmd.setStorageIpAddressDeux(agentHost.getStorageIpAddress());
    cmd.setStorageNetmaskDeux(agentHost.getStorageNetMask());
    cmd.setStorageMacAddressDeux(agentHost.getStorageIpAddress());
    cmd.setName(agentHost.getName());
    cmd.setGuid(agentHost.getGuid());
    cmd.setVersion(agentHost.getVersion());
    cmd.setAgentTag("agent-simulator");
    cmd.setDataCenter(String.valueOf(agentHost.getDataCenterId()));
    cmd.setPod(String.valueOf(agentHost.getPodId()));
    cmd.setCluster(String.valueOf(agentHost.getClusterId()));
    StartupStorageCommand ssCmd = initializeLocalSR();
    return new StartupCommand[] { cmd, ssCmd };
}
Also used : HashMap(java.util.HashMap) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) RouterPrivateIpStrategy(com.cloud.network.Networks.RouterPrivateIpStrategy) MockVMVO(com.cloud.simulator.MockVMVO) StartupCommand(com.cloud.agent.api.StartupCommand) State(com.cloud.vm.VirtualMachine.State) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

StartupStorageCommand (com.cloud.agent.api.StartupStorageCommand)22 StartupCommand (com.cloud.agent.api.StartupCommand)14 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)12 StoragePoolInfo (com.cloud.agent.api.StoragePoolInfo)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 HashMap (java.util.HashMap)3 Command (com.cloud.agent.api.Command)2 PingCommand (com.cloud.agent.api.PingCommand)2 PingRoutingCommand (com.cloud.agent.api.PingRoutingCommand)2 VmState (com.cloud.agent.api.StartupRoutingCommand.VmState)2 CloudException (com.cloud.exception.CloudException)2 InternalErrorException (com.cloud.exception.InternalErrorException)2 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)2 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)2 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)2 RouterPrivateIpStrategy (com.cloud.network.Networks.RouterPrivateIpStrategy)2 MockVMVO (com.cloud.simulator.MockVMVO)2 TemplateProp (com.cloud.storage.template.TemplateProp)2 State (com.cloud.vm.VirtualMachine.State)2 IOException (java.io.IOException)2