Search in sources :

Example 1 with ProviderResponse

use of org.apache.cloudstack.api.response.ProviderResponse in project cloudstack by apache.

the class ApiResponseHelper method createVpcResponse.

@Override
public VpcResponse createVpcResponse(ResponseView view, Vpc vpc) {
    VpcResponse response = new VpcResponse();
    response.setId(vpc.getUuid());
    response.setName(vpc.getName());
    response.setDisplayText(vpc.getDisplayText());
    response.setState(vpc.getState().name());
    VpcOffering voff = ApiDBUtils.findVpcOfferingById(vpc.getVpcOfferingId());
    if (voff != null) {
        response.setVpcOfferingId(voff.getUuid());
    }
    response.setCidr(vpc.getCidr());
    response.setRestartRequired(vpc.isRestartRequired());
    response.setNetworkDomain(vpc.getNetworkDomain());
    response.setForDisplay(vpc.isDisplay());
    response.setUsesDistributedRouter(vpc.usesDistributedRouter());
    response.setRedundantRouter(vpc.isRedundant());
    response.setRegionLevelVpc(vpc.isRegionLevelVpc());
    Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId());
    List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
    for (Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
        Service service = entry.getKey();
        Set<Provider> serviceProviders = entry.getValue();
        ServiceResponse svcRsp = new ServiceResponse();
        // skip gateway service
        if (service == Service.Gateway) {
            continue;
        }
        svcRsp.setName(service.getName());
        List<ProviderResponse> providers = new ArrayList<ProviderResponse>();
        for (Provider provider : serviceProviders) {
            if (provider != null) {
                ProviderResponse providerRsp = new ProviderResponse();
                providerRsp.setName(provider.getName());
                providers.add(providerRsp);
            }
        }
        svcRsp.setProviders(providers);
        serviceResponses.add(svcRsp);
    }
    List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();
    List<? extends Network> networks = ApiDBUtils.listVpcNetworks(vpc.getId());
    for (Network network : networks) {
        NetworkResponse ntwkRsp = createNetworkResponse(view, network);
        networkResponses.add(ntwkRsp);
    }
    DataCenter zone = ApiDBUtils.findZoneById(vpc.getZoneId());
    if (zone != null) {
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    response.setNetworks(networkResponses);
    response.setServices(serviceResponses);
    populateOwner(response, vpc);
    // set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Vpc, vpc.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    response.setTags(tagResponses);
    response.setObjectName("vpc");
    return response;
}
Also used : EnumSet(java.util.EnumSet) HashSet(java.util.HashSet) Set(java.util.Set) ProviderResponse(org.apache.cloudstack.api.response.ProviderResponse) VirtualRouterProviderResponse(org.apache.cloudstack.api.response.VirtualRouterProviderResponse) OvsProviderResponse(org.apache.cloudstack.api.response.OvsProviderResponse) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UsageService(org.apache.cloudstack.usage.UsageService) OvsProvider(com.cloud.network.OvsProvider) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) Provider(com.cloud.network.Network.Provider) ServiceResponse(org.apache.cloudstack.api.response.ServiceResponse) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) VpcResponse(org.apache.cloudstack.api.response.VpcResponse) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) VpcOffering(com.cloud.network.vpc.VpcOffering) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse) PhysicalNetworkResponse(org.apache.cloudstack.api.response.PhysicalNetworkResponse) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with ProviderResponse

use of org.apache.cloudstack.api.response.ProviderResponse in project cloudstack by apache.

the class ApiResponseHelper method createVpcOfferingResponse.

@Override
public VpcOfferingResponse createVpcOfferingResponse(VpcOffering offering) {
    VpcOfferingResponse response = new VpcOfferingResponse();
    response.setId(offering.getUuid());
    response.setName(offering.getName());
    response.setDisplayText(offering.getDisplayText());
    response.setIsDefault(offering.isDefault());
    response.setState(offering.getState().name());
    response.setSupportsDistributedRouter(offering.supportsDistributedRouter());
    response.setSupportsRegionLevelVpc(offering.offersRegionLevelVPC());
    Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(offering.getId());
    List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
    for (Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
        Service service = entry.getKey();
        Set<Provider> srvc_providers = entry.getValue();
        ServiceResponse svcRsp = new ServiceResponse();
        // skip gateway service
        if (service == Service.Gateway) {
            continue;
        }
        svcRsp.setName(service.getName());
        List<ProviderResponse> providers = new ArrayList<ProviderResponse>();
        for (Provider provider : srvc_providers) {
            if (provider != null) {
                ProviderResponse providerRsp = new ProviderResponse();
                providerRsp.setName(provider.getName());
                providers.add(providerRsp);
            }
        }
        svcRsp.setProviders(providers);
        serviceResponses.add(svcRsp);
    }
    response.setServices(serviceResponses);
    response.setObjectName("vpcoffering");
    return response;
}
Also used : VpcOfferingResponse(org.apache.cloudstack.api.response.VpcOfferingResponse) EnumSet(java.util.EnumSet) HashSet(java.util.HashSet) Set(java.util.Set) ProviderResponse(org.apache.cloudstack.api.response.ProviderResponse) VirtualRouterProviderResponse(org.apache.cloudstack.api.response.VirtualRouterProviderResponse) OvsProviderResponse(org.apache.cloudstack.api.response.OvsProviderResponse) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UsageService(org.apache.cloudstack.usage.UsageService) OvsProvider(com.cloud.network.OvsProvider) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) Provider(com.cloud.network.Network.Provider) ServiceResponse(org.apache.cloudstack.api.response.ServiceResponse) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with ProviderResponse

use of org.apache.cloudstack.api.response.ProviderResponse in project cloudstack by apache.

the class ApiResponseHelper method createNetworkServiceResponse.

@Override
public ServiceResponse createNetworkServiceResponse(Service service) {
    ServiceResponse response = new ServiceResponse();
    response.setName(service.getName());
    // set list of capabilities required for the service
    List<CapabilityResponse> capabilityResponses = new ArrayList<CapabilityResponse>();
    Capability[] capabilities = service.getCapabilities();
    for (Capability cap : capabilities) {
        CapabilityResponse capabilityResponse = new CapabilityResponse();
        capabilityResponse.setName(cap.getName());
        capabilityResponse.setObjectName("capability");
        if (cap.getName().equals(Capability.SupportedLBIsolation.getName()) || cap.getName().equals(Capability.SupportedSourceNatTypes.getName()) || cap.getName().equals(Capability.RedundantRouter.getName())) {
            capabilityResponse.setCanChoose(true);
        } else {
            capabilityResponse.setCanChoose(false);
        }
        capabilityResponses.add(capabilityResponse);
    }
    response.setCapabilities(capabilityResponses);
    // set list of providers providing this service
    List<? extends Network.Provider> serviceProviders = ApiDBUtils.getProvidersForService(service);
    List<ProviderResponse> serviceProvidersResponses = new ArrayList<ProviderResponse>();
    for (Network.Provider serviceProvider : serviceProviders) {
        // return only Virtual Router/JuniperSRX/CiscoVnmc as a provider for the firewall
        if (service == Service.Firewall && !(serviceProvider == Provider.VirtualRouter || serviceProvider == Provider.JuniperSRX || serviceProvider == Provider.CiscoVnmc || serviceProvider == Provider.PaloAlto || serviceProvider == Provider.NuageVsp || serviceProvider == Provider.BigSwitchBcf)) {
            continue;
        }
        ProviderResponse serviceProviderResponse = createServiceProviderResponse(serviceProvider);
        serviceProvidersResponses.add(serviceProviderResponse);
    }
    response.setProviders(serviceProvidersResponses);
    response.setObjectName("networkservice");
    return response;
}
Also used : ServiceResponse(org.apache.cloudstack.api.response.ServiceResponse) ProviderResponse(org.apache.cloudstack.api.response.ProviderResponse) VirtualRouterProviderResponse(org.apache.cloudstack.api.response.VirtualRouterProviderResponse) OvsProviderResponse(org.apache.cloudstack.api.response.OvsProviderResponse) Capability(com.cloud.network.Network.Capability) Provider(com.cloud.network.Network.Provider) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ArrayList(java.util.ArrayList) CapabilityResponse(org.apache.cloudstack.api.response.CapabilityResponse)

Example 4 with ProviderResponse

use of org.apache.cloudstack.api.response.ProviderResponse in project cloudstack by apache.

the class ApiResponseHelper method createNetworkOfferingResponse.

@Override
public NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering offering) {
    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());
    response.setSupportsPublicAccess(offering.getSupportsPublicAccess());
    Long so = null;
    if (offering.getServiceOfferingId() != null) {
        so = offering.getServiceOfferingId();
    } else {
        so = ApiDBUtils.findDefaultRouterServiceOffering();
    }
    if (so != null) {
        ServiceOffering soffering = ApiDBUtils.findServiceOfferingById(so);
        if (soffering != null) {
            response.setServiceOfferingId(soffering.getUuid());
        }
    }
    if (offering.getGuestType() != null) {
        response.setGuestIpType(offering.getGuestType().toString());
    }
    response.setState(offering.getState().name());
    Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listNetworkOfferingServices(offering.getId());
    List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
    for (Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
        Service service = entry.getKey();
        Set<Provider> srvc_providers = entry.getValue();
        ServiceResponse svcRsp = new ServiceResponse();
        // skip gateway service
        if (service == Service.Gateway) {
            continue;
        }
        svcRsp.setName(service.getName());
        List<ProviderResponse> providers = new ArrayList<ProviderResponse>();
        for (Provider provider : srvc_providers) {
            if (provider != null) {
                ProviderResponse providerRsp = new ProviderResponse();
                providerRsp.setName(provider.getName());
                providers.add(providerRsp);
            }
        }
        svcRsp.setProviders(providers);
        if (Service.Lb == service) {
            List<CapabilityResponse> lbCapResponse = new ArrayList<CapabilityResponse>();
            CapabilityResponse lbIsoaltion = new CapabilityResponse();
            lbIsoaltion.setName(Capability.SupportedLBIsolation.getName());
            lbIsoaltion.setValue(offering.getDedicatedLB() ? "dedicated" : "shared");
            lbCapResponse.add(lbIsoaltion);
            CapabilityResponse eLb = new CapabilityResponse();
            eLb.setName(Capability.ElasticLb.getName());
            eLb.setValue(offering.getElasticLb() ? "true" : "false");
            lbCapResponse.add(eLb);
            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) {
            List<CapabilityResponse> capabilities = new ArrayList<CapabilityResponse>();
            CapabilityResponse sharedSourceNat = new CapabilityResponse();
            sharedSourceNat.setName(Capability.SupportedSourceNatTypes.getName());
            sharedSourceNat.setValue(offering.getSharedSourceNat() ? "perzone" : "peraccount");
            capabilities.add(sharedSourceNat);
            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) {
            List<CapabilityResponse> staticNatCapResponse = new ArrayList<CapabilityResponse>();
            CapabilityResponse eIp = new CapabilityResponse();
            eIp.setName(Capability.ElasticIp.getName());
            eIp.setValue(offering.getElasticIp() ? "true" : "false");
            staticNatCapResponse.add(eIp);
            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
    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) ProviderResponse(org.apache.cloudstack.api.response.ProviderResponse) VirtualRouterProviderResponse(org.apache.cloudstack.api.response.VirtualRouterProviderResponse) OvsProviderResponse(org.apache.cloudstack.api.response.OvsProviderResponse) NetworkOfferingResponse(org.apache.cloudstack.api.response.NetworkOfferingResponse) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UsageService(org.apache.cloudstack.usage.UsageService) CapabilityResponse(org.apache.cloudstack.api.response.CapabilityResponse) OvsProvider(com.cloud.network.OvsProvider) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) Provider(com.cloud.network.Network.Provider) ServiceResponse(org.apache.cloudstack.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 5 with ProviderResponse

use of org.apache.cloudstack.api.response.ProviderResponse in project cloudstack by apache.

the class UpdateNetworkServiceProviderCmd method execute.

@Override
public void execute() {
    PhysicalNetworkServiceProvider result = _networkService.updateNetworkServiceProvider(getId(), getState(), getEnabledServices());
    if (result != null) {
        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(org.apache.cloudstack.api.response.ProviderResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider)

Aggregations

ProviderResponse (org.apache.cloudstack.api.response.ProviderResponse)9 PhysicalNetworkServiceProvider (com.cloud.network.PhysicalNetworkServiceProvider)7 ArrayList (java.util.ArrayList)6 OvsProviderResponse (org.apache.cloudstack.api.response.OvsProviderResponse)6 VirtualRouterProviderResponse (org.apache.cloudstack.api.response.VirtualRouterProviderResponse)6 Provider (com.cloud.network.Network.Provider)5 Service (com.cloud.network.Network.Service)4 OvsProvider (com.cloud.network.OvsProvider)4 VirtualRouterProvider (com.cloud.network.VirtualRouterProvider)4 ServiceResponse (org.apache.cloudstack.api.response.ServiceResponse)4 UsageService (org.apache.cloudstack.usage.UsageService)4 PhysicalNetwork (com.cloud.network.PhysicalNetwork)3 EnumSet (java.util.EnumSet)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Set (java.util.Set)3 Network (com.cloud.network.Network)2 List (java.util.List)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2