Search in sources :

Example 36 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class NetworkUsageManagerImpl method addTrafficMonitor.

@Override
public Host addTrafficMonitor(AddTrafficMonitorCmd cmd) {
    long zoneId = cmd.getZoneId();
    DataCenterVO zone = _dcDao.findById(zoneId);
    String zoneName;
    if (zone == null) {
        throw new InvalidParameterValueException("Could not find zone with ID: " + zoneId);
    } else {
        zoneName = zone.getName();
    }
    List<HostVO> trafficMonitorsInZone = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.TrafficMonitor, zoneId);
    if (trafficMonitorsInZone.size() != 0) {
        throw new InvalidParameterValueException("Already added an traffic monitor in zone: " + zoneName);
    }
    URI uri;
    try {
        uri = new URI(cmd.getUrl());
    } catch (Exception e) {
        s_logger.debug(e);
        throw new InvalidParameterValueException(e.getMessage());
    }
    String ipAddress = uri.getHost();
    // String numRetries = params.get("numretries");
    // String timeout = params.get("timeout");
    TrafficSentinelResource resource = new TrafficSentinelResource();
    String guid = getTrafficMonitorGuid(zoneId, NetworkUsageResourceName.TrafficSentinel, ipAddress);
    Map<String, Object> hostParams = new HashMap<String, Object>();
    hostParams.put("zone", String.valueOf(zoneId));
    hostParams.put("ipaddress", ipAddress);
    hostParams.put("url", cmd.getUrl());
    hostParams.put("inclZones", (cmd.getInclZones() != null) ? cmd.getInclZones() : _TSinclZones);
    hostParams.put("exclZones", (cmd.getExclZones() != null) ? cmd.getExclZones() : _TSexclZones);
    hostParams.put("guid", guid);
    hostParams.put("name", guid);
    try {
        resource.configure(guid, hostParams);
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
    Map<String, String> hostDetails = new HashMap<String, String>();
    hostDetails.put("url", cmd.getUrl());
    hostDetails.put("last_collection", "" + System.currentTimeMillis());
    if (cmd.getInclZones() != null) {
        hostDetails.put("inclZones", cmd.getInclZones());
    }
    if (cmd.getExclZones() != null) {
        hostDetails.put("exclZones", cmd.getExclZones());
    }
    Host trafficMonitor = _resourceMgr.addHost(zoneId, resource, Host.Type.TrafficMonitor, hostDetails);
    return trafficMonitor;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) Host(com.cloud.host.Host) URI(java.net.URI) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TrafficSentinelResource(com.cloud.network.resource.TrafficSentinelResource)

Example 37 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class IssueOutOfBandManagementPowerActionCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    final Host host = _resourceService.getHost(getHostId());
    if (host == null) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find host by ID: " + getHostId());
    }
    final PowerOperation powerOperation = PowerOperation.valueOf(getPowerAction());
    CallContext.current().setEventDetails("Host Id: " + host.getId() + " Action: " + powerOperation.toString());
    CallContext.current().putContextParameter(Host.class, host.getUuid());
    final OutOfBandManagementResponse response = outOfBandManagementService.executePowerOperation(host, powerOperation, getActionTimeout());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : OutOfBandManagementResponse(org.apache.cloudstack.api.response.OutOfBandManagementResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Host(com.cloud.host.Host) PowerOperation(org.apache.cloudstack.outofbandmanagement.OutOfBandManagement.PowerOperation)

Example 38 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class ConfigureOutOfBandManagementCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    final Host host = _resourceService.getHost(getHostId());
    if (host == null) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find host by ID: " + getHostId());
    }
    CallContext.current().putContextParameter(Host.class, host.getUuid());
    final OutOfBandManagementResponse response = outOfBandManagementService.configure(host, getHostPMOptions());
    response.setId(host.getUuid());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : OutOfBandManagementResponse(org.apache.cloudstack.api.response.OutOfBandManagementResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Host(com.cloud.host.Host)

Example 39 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class AddNetworkDeviceCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        Host device = nwDeviceMgr.addNetworkDevice(this);
        NetworkDeviceResponse response = nwDeviceMgr.getApiResponse(device);
        response.setObjectName("networkdevice");
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (InvalidParameterValueException ipve) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage());
    } catch (CloudRuntimeException cre) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkDeviceResponse(org.apache.cloudstack.api.response.NetworkDeviceResponse) Host(com.cloud.host.Host)

Example 40 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class VirtualMachineManagerImpl method orchestrateMigrateAway.

private void orchestrateMigrateAway(final String vmUuid, final long srcHostId, final DeploymentPlanner planner) throws InsufficientServerCapacityException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    if (vm == null) {
        String message = String.format("Unable to find VM with uuid [%s].", vmUuid);
        s_logger.warn(message);
        throw new CloudRuntimeException(message);
    }
    ServiceOfferingVO offeringVO = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offeringVO, null, null);
    final Long hostId = vm.getHostId();
    if (hostId == null) {
        String message = String.format("Unable to migrate %s due to it does not have a host id.", vm.toString());
        s_logger.warn(message);
        throw new CloudRuntimeException(message);
    }
    final Host host = _hostDao.findById(hostId);
    Long poolId = null;
    final List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
    for (final VolumeVO rootVolumeOfVm : vols) {
        final StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());
        if (rootDiskPool != null) {
            poolId = rootDiskPool.getId();
        }
    }
    final ExcludeList excludes = new ExcludeList();
    excludes.addHost(hostId);
    DataCenterDeployment plan = getMigrationDeployment(vm, host, poolId, excludes);
    DeployDestination dest = null;
    while (true) {
        try {
            plan.setMigrationPlan(true);
            dest = _dpMgr.planDeployment(profile, plan, excludes, planner);
        } catch (final AffinityConflictException e2) {
            String message = String.format("Unable to create deployment, affinity rules associted to the %s conflict.", vm.toString());
            s_logger.warn(message, e2);
            throw new CloudRuntimeException(message, e2);
        }
        if (dest == null) {
            s_logger.warn("Unable to find destination for migrating the vm " + profile);
            throw new InsufficientServerCapacityException("Unable to find a server to migrate to.", DataCenter.class, host.getDataCenterId());
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Found destination " + dest + " for migrating to.");
        }
        excludes.addHost(dest.getHost().getId());
        try {
            migrate(vm, srcHostId, dest);
            return;
        } catch (ResourceUnavailableException | ConcurrentOperationException e) {
            s_logger.warn(String.format("Unable to migrate %s to %s due to [%s]", vm.toString(), dest.getHost().toString(), e.getMessage()), e);
        }
        try {
            advanceStop(vmUuid, true);
            throw new CloudRuntimeException("Unable to migrate " + vm);
        } catch (final ResourceUnavailableException | ConcurrentOperationException | OperationTimedoutException e) {
            s_logger.error(String.format("Unable to stop %s due to [%s].", vm.toString(), e.getMessage()), e);
            throw new CloudRuntimeException("Unable to migrate " + vm);
        }
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) Host(com.cloud.host.Host) AffinityConflictException(com.cloud.exception.AffinityConflictException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeployDestination(com.cloud.deploy.DeployDestination) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Aggregations

Host (com.cloud.host.Host)226 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)77 ArrayList (java.util.ArrayList)67 HashMap (java.util.HashMap)50 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)42 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)31 ServerApiException (org.apache.cloudstack.api.ServerApiException)30 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)28 Answer (com.cloud.agent.api.Answer)25 ConfigurationException (javax.naming.ConfigurationException)25 Pair (com.cloud.utils.Pair)24 Map (java.util.Map)24 StoragePool (com.cloud.storage.StoragePool)23 DeployDestination (com.cloud.deploy.DeployDestination)22 HostVO (com.cloud.host.HostVO)22 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)21 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)21 VolumeVO (com.cloud.storage.VolumeVO)21 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)20 List (java.util.List)20