Search in sources :

Example 56 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class UpgradeVMCmd method execute.

@Override
public void execute() throws ResourceAllocationException {
    CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
    ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
    if (serviceOffering == null) {
        throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
    }
    UserVm result = _userVmService.upgradeVirtualMachine(this);
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade vm");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) ServiceOffering(com.cloud.offering.ServiceOffering) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 57 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project CloudStack-archive by CloudStack-extras.

the class ListServiceOfferingsCmd method execute.

@Override
public void execute() {
    List<? extends ServiceOffering> offerings = _mgr.searchForServiceOfferings(this);
    ListResponse<ServiceOfferingResponse> response = new ListResponse<ServiceOfferingResponse>();
    List<ServiceOfferingResponse> offeringResponses = new ArrayList<ServiceOfferingResponse>();
    for (ServiceOffering offering : offerings) {
        ServiceOfferingResponse offeringResponse = _responseGenerator.createServiceOfferingResponse(offering);
        offeringResponse.setObjectName("serviceoffering");
        offeringResponses.add(offeringResponse);
    }
    response.setResponses(offeringResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ServiceOfferingResponse(com.cloud.api.response.ServiceOfferingResponse) ListResponse(com.cloud.api.response.ListResponse) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList)

Example 58 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project CloudStack-archive by CloudStack-extras.

the class UpdateServiceOfferingCmd method execute.

@Override
public void execute() {
    //Note
    //Once an offering is created, we cannot update the domainId field (keeping consistent with zones logic)
    ServiceOffering result = _configService.updateServiceOffering(this);
    if (result != null) {
        ServiceOfferingResponse response = _responseGenerator.createServiceOfferingResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update service offering");
    }
}
Also used : ServiceOfferingResponse(com.cloud.api.response.ServiceOfferingResponse) ServerApiException(com.cloud.api.ServerApiException) ServiceOffering(com.cloud.offering.ServiceOffering)

Example 59 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project CloudStack-archive by CloudStack-extras.

the class CreateServiceOfferingCmd method execute.

@Override
public void execute() {
    ServiceOffering result = _configService.createServiceOffering(this);
    if (result != null) {
        ServiceOfferingResponse response = _responseGenerator.createServiceOfferingResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create service offering");
    }
}
Also used : ServiceOfferingResponse(com.cloud.api.response.ServiceOfferingResponse) ServerApiException(com.cloud.api.ServerApiException) ServiceOffering(com.cloud.offering.ServiceOffering)

Example 60 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class RandomAllocator method allocateTo.

@Override
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List<? extends Host> hosts, int returnUpTo, boolean considerReservedCapacity) {
    long dcId = plan.getDataCenterId();
    Long podId = plan.getPodId();
    Long clusterId = plan.getClusterId();
    ServiceOffering offering = vmProfile.getServiceOffering();
    List<Host> suitableHosts = new ArrayList<Host>();
    List<Host> hostsCopy = new ArrayList<Host>(hosts);
    if (type == Host.Type.Storage) {
        return suitableHosts;
    }
    String hostTag = offering.getHostTag();
    if (hostTag != null) {
        s_logger.debug("Looking for hosts in dc: " + dcId + "  pod:" + podId + "  cluster:" + clusterId + " having host tag:" + hostTag);
    } else {
        s_logger.debug("Looking for hosts in dc: " + dcId + "  pod:" + podId + "  cluster:" + clusterId);
    }
    // list all computing hosts, regardless of whether they support routing...it's random after all
    if (hostTag != null) {
        hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag));
    } else {
        hostsCopy.retainAll(_resourceMgr.listAllUpAndEnabledHosts(type, clusterId, podId, dcId));
    }
    s_logger.debug("Random Allocator found " + hostsCopy.size() + "  hosts");
    if (hostsCopy.size() == 0) {
        return suitableHosts;
    }
    Collections.shuffle(hostsCopy);
    for (Host host : hostsCopy) {
        if (suitableHosts.size() == returnUpTo) {
            break;
        }
        if (!avoid.shouldAvoid(host)) {
            suitableHosts.add(host);
        } else {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Host name: " + host.getName() + ", hostId: " + host.getId() + " is in avoid set, " + "skipping this and trying other available hosts");
            }
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Random Host Allocator returning " + suitableHosts.size() + " suitable hosts");
    }
    return suitableHosts;
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host)

Aggregations

ServiceOffering (com.cloud.offering.ServiceOffering)103 ArrayList (java.util.ArrayList)34 Account (com.cloud.user.Account)30 DataCenter (com.cloud.dc.DataCenter)23 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 HashMap (java.util.HashMap)18 VirtualMachine (com.cloud.vm.VirtualMachine)17 VMTemplateVO (com.cloud.storage.VMTemplateVO)14 UserVm (com.cloud.uservm.UserVm)14 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 Map (java.util.Map)14 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)13 ServerApiException (com.cloud.api.ServerApiException)12 HostVO (com.cloud.host.HostVO)12 DiskOffering (com.cloud.offering.DiskOffering)11 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)11 Host (com.cloud.host.Host)10 Network (com.cloud.network.Network)10 List (java.util.List)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9