Search in sources :

Example 11 with ProviderResponse

use of com.cloud.api.response.ProviderResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createNetworkOfferingResponse.

@Override
public NetworkOfferingResponse createNetworkOfferingResponse(final NetworkOffering offering) {
    final NetworkOfferingResponse response = new NetworkOfferingResponse();
    response.setId(offering.getUuid());
    response.setName(offering.getName());
    response.setDisplayText(offering.getDisplayText());
    response.setTags(offering.getTags());
    response.setTrafficType(offering.getTrafficType().toString());
    response.setIsDefault(offering.isDefault());
    response.setSpecifyVlan(offering.getSpecifyVlan());
    response.setConserveMode(offering.isConserveMode());
    response.setSpecifyIpRanges(offering.getSpecifyIpRanges());
    response.setAvailability(offering.getAvailability().toString());
    response.setIsPersistent(offering.getIsPersistent());
    response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId()));
    response.setEgressDefaultPolicy(offering.getEgressDefaultPolicy());
    response.setConcurrentConnections(offering.getConcurrentConnections());
    response.setSupportsStrechedL2Subnet(offering.getSupportsStrechedL2());
    final Long so;
    if (offering.getServiceOfferingId() != null) {
        so = offering.getServiceOfferingId();
    } else {
        so = ApiDBUtils.findDefaultRouterServiceOffering();
    }
    if (so != null) {
        final ServiceOffering serviceOffering = ApiDBUtils.findServiceOfferingById(so);
        if (serviceOffering != null) {
            response.setServiceOfferingId(serviceOffering.getUuid());
            response.setServiceOfferingName(serviceOffering.getName());
        }
    }
    final ServiceOffering secondaryServiceOffering = _serviceOfferingDao.findById(offering.getSecondaryServiceOfferingId());
    if (secondaryServiceOffering != null) {
        response.setSecondaryServiceOfferingId(secondaryServiceOffering.getUuid());
        response.setSecondaryServiceOfferingName(secondaryServiceOffering.getName());
    }
    if (offering.getGuestType() != null) {
        response.setGuestIpType(offering.getGuestType().toString());
    }
    response.setState(offering.getState().name());
    final Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listNetworkOfferingServices(offering.getId());
    final List<ServiceResponse> serviceResponses = new ArrayList<>();
    for (final Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
        final Service service = entry.getKey();
        final Set<Provider> srvc_providers = entry.getValue();
        final ServiceResponse svcRsp = new ServiceResponse();
        // skip gateway service
        if (service == Service.Gateway) {
            continue;
        }
        svcRsp.setName(service.getName());
        final List<ProviderResponse> providers = getProviderResponses(srvc_providers);
        svcRsp.setProviders(providers);
        if (Service.Lb == service) {
            final List<CapabilityResponse> lbCapResponse = new ArrayList<>();
            final CapabilityResponse lbIsoaltion = new CapabilityResponse();
            lbIsoaltion.setName(Capability.SupportedLBIsolation.getName());
            lbIsoaltion.setValue(offering.getDedicatedLB() ? "dedicated" : "shared");
            lbCapResponse.add(lbIsoaltion);
            final CapabilityResponse eLb = new CapabilityResponse();
            eLb.setName(Capability.ElasticLb.getName());
            eLb.setValue(offering.getElasticLb() ? "true" : "false");
            lbCapResponse.add(eLb);
            final CapabilityResponse inline = new CapabilityResponse();
            inline.setName(Capability.InlineMode.getName());
            inline.setValue(offering.isInline() ? "true" : "false");
            lbCapResponse.add(inline);
            svcRsp.setCapabilities(lbCapResponse);
        } else if (Service.SourceNat == service) {
            final List<CapabilityResponse> capabilities = new ArrayList<>();
            final CapabilityResponse sharedSourceNat = new CapabilityResponse();
            sharedSourceNat.setName(Capability.SupportedSourceNatTypes.getName());
            sharedSourceNat.setValue(offering.getSharedSourceNat() ? "perzone" : "peraccount");
            capabilities.add(sharedSourceNat);
            final CapabilityResponse redundantRouter = new CapabilityResponse();
            redundantRouter.setName(Capability.RedundantRouter.getName());
            redundantRouter.setValue(offering.getRedundantRouter() ? "true" : "false");
            capabilities.add(redundantRouter);
            svcRsp.setCapabilities(capabilities);
        } else if (service == Service.StaticNat) {
            final List<CapabilityResponse> staticNatCapResponse = new ArrayList<>();
            final CapabilityResponse eIp = new CapabilityResponse();
            eIp.setName(Capability.ElasticIp.getName());
            eIp.setValue(offering.getElasticIp() ? "true" : "false");
            staticNatCapResponse.add(eIp);
            final CapabilityResponse associatePublicIp = new CapabilityResponse();
            associatePublicIp.setName(Capability.AssociatePublicIP.getName());
            associatePublicIp.setValue(offering.getAssociatePublicIP() ? "true" : "false");
            staticNatCapResponse.add(associatePublicIp);
            svcRsp.setCapabilities(staticNatCapResponse);
        }
        serviceResponses.add(svcRsp);
    }
    response.setForVpc(_configMgr.isOfferingForVpc(offering));
    response.setServices(serviceResponses);
    // set network offering details
    final Map<Detail, String> details = _ntwkModel.getNtwkOffDetails(offering.getId());
    if (details != null && !details.isEmpty()) {
        response.setDetails(details);
    }
    response.setObjectName("networkoffering");
    return response;
}
Also used : EnumSet(java.util.EnumSet) HashSet(java.util.HashSet) Set(java.util.Set) VirtualRouterProviderResponse(com.cloud.api.response.VirtualRouterProviderResponse) ProviderResponse(com.cloud.api.response.ProviderResponse) NetworkOfferingResponse(com.cloud.api.response.NetworkOfferingResponse) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) CapabilityResponse(com.cloud.api.response.CapabilityResponse) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) Provider(com.cloud.network.Network.Provider) ServiceResponse(com.cloud.api.response.ServiceResponse) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) Detail(com.cloud.offering.NetworkOffering.Detail)

Example 12 with ProviderResponse

use of com.cloud.api.response.ProviderResponse in project cosmic by MissionCriticalCloud.

the class UpdateNetworkServiceProviderCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final PhysicalNetworkServiceProvider result = _networkService.updateNetworkServiceProvider(getId(), getState(), getEnabledServices());
    if (result != null) {
        final ProviderResponse response = _responseGenerator.createNetworkServiceProviderResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update service provider");
    }
}
Also used : ProviderResponse(com.cloud.api.response.ProviderResponse) ServerApiException(com.cloud.api.ServerApiException) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider)

Aggregations

ProviderResponse (com.cloud.api.response.ProviderResponse)12 PhysicalNetworkServiceProvider (com.cloud.network.PhysicalNetworkServiceProvider)10 ArrayList (java.util.ArrayList)7 VirtualRouterProviderResponse (com.cloud.api.response.VirtualRouterProviderResponse)6 Provider (com.cloud.network.Network.Provider)5 ServerApiException (com.cloud.api.ServerApiException)4 VirtualRouterProvider (com.cloud.network.VirtualRouterProvider)4 ServiceResponse (com.cloud.api.response.ServiceResponse)3 Service (com.cloud.network.Network.Service)3 CapabilityResponse (com.cloud.api.response.CapabilityResponse)2 ListResponse (com.cloud.api.response.ListResponse)2 PhysicalNetwork (com.cloud.network.PhysicalNetwork)2 EnumSet (java.util.EnumSet)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 NetworkOfferingResponse (com.cloud.api.response.NetworkOfferingResponse)1 Network (com.cloud.network.Network)1