use of org.apache.cloudstack.api.response.ResourceTagResponse 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.setCreated(vpc.getCreated());
response.setState(vpc.getState().name());
VpcOffering voff = ApiDBUtils.findVpcOfferingById(vpc.getVpcOfferingId());
if (voff != null) {
response.setVpcOfferingId(voff.getUuid());
response.setVpcOfferingName(voff.getName());
}
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.setHasAnnotation(annotationDao.hasAnnotations(vpc.getUuid(), AnnotationService.EntityType.VPC.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
response.setObjectName("vpc");
return response;
}
use of org.apache.cloudstack.api.response.ResourceTagResponse in project cloudstack by apache.
the class ApiResponseHelper method createLoadBalancerContainerReponse.
@Override
public ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(ApplicationLoadBalancerRule lb, Map<Ip, UserVm> lbInstances) {
ApplicationLoadBalancerResponse lbResponse = new ApplicationLoadBalancerResponse();
lbResponse.setId(lb.getUuid());
lbResponse.setName(lb.getName());
lbResponse.setDescription(lb.getDescription());
lbResponse.setAlgorithm(lb.getAlgorithm());
lbResponse.setForDisplay(lb.isDisplay());
Network nw = ApiDBUtils.findNetworkById(lb.getNetworkId());
lbResponse.setNetworkId(nw.getUuid());
populateOwner(lbResponse, lb);
if (lb.getScheme() == Scheme.Internal) {
lbResponse.setSourceIp(lb.getSourceIp().addr());
// TODO - create the view for the load balancer rule to reflect the network uuid
Network network = ApiDBUtils.findNetworkById(lb.getNetworkId());
lbResponse.setSourceIpNetworkId(network.getUuid());
} else {
// for public, populate the ip information from the ip address
IpAddress publicIp = ApiDBUtils.findIpAddressById(lb.getSourceIpAddressId());
lbResponse.setSourceIp(publicIp.getAddress().addr());
Network ntwk = ApiDBUtils.findNetworkById(publicIp.getNetworkId());
lbResponse.setSourceIpNetworkId(ntwk.getUuid());
}
// set load balancer rules information (only one rule per load balancer in this release)
List<ApplicationLoadBalancerRuleResponse> ruleResponses = new ArrayList<ApplicationLoadBalancerRuleResponse>();
ApplicationLoadBalancerRuleResponse ruleResponse = new ApplicationLoadBalancerRuleResponse();
ruleResponse.setInstancePort(lb.getDefaultPortStart());
ruleResponse.setSourcePort(lb.getSourcePortStart());
FirewallRule.State stateToSet = lb.getState();
if (stateToSet.equals(FirewallRule.State.Revoke)) {
stateToSet = FirewallRule.State.Deleting;
}
ruleResponse.setState(stateToSet.toString());
ruleResponse.setObjectName("loadbalancerrule");
ruleResponses.add(ruleResponse);
lbResponse.setLbRules(ruleResponses);
// set Lb instances information
List<ApplicationLoadBalancerInstanceResponse> instanceResponses = new ArrayList<ApplicationLoadBalancerInstanceResponse>();
for (Map.Entry<Ip, UserVm> entry : lbInstances.entrySet()) {
Ip ip = entry.getKey();
UserVm vm = entry.getValue();
ApplicationLoadBalancerInstanceResponse instanceResponse = new ApplicationLoadBalancerInstanceResponse();
instanceResponse.setIpAddress(ip.addr());
instanceResponse.setId(vm.getUuid());
instanceResponse.setName(vm.getInstanceName());
instanceResponse.setObjectName("loadbalancerinstance");
instanceResponses.add(instanceResponse);
}
lbResponse.setLbInstances(instanceResponses);
// set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.LoadBalancer, lb.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
}
lbResponse.setTags(tagResponses);
lbResponse.setObjectName("loadbalancer");
return lbResponse;
}
use of org.apache.cloudstack.api.response.ResourceTagResponse in project cloudstack by apache.
the class SecurityGroupJoinDaoImpl method setSecurityGroupResponse.
@Override
public SecurityGroupResponse setSecurityGroupResponse(SecurityGroupResponse vsgData, SecurityGroupJoinVO vsg) {
Long rule_id = vsg.getRuleId();
if (rule_id != null && rule_id.longValue() > 0) {
SecurityGroupRuleResponse ruleData = new SecurityGroupRuleResponse();
ruleData.setRuleId(vsg.getRuleUuid());
ruleData.setProtocol(vsg.getRuleProtocol());
if ("icmp".equalsIgnoreCase(vsg.getRuleProtocol())) {
ruleData.setIcmpType(vsg.getRuleStartPort());
ruleData.setIcmpCode(vsg.getRuleEndPort());
} else {
ruleData.setStartPort(vsg.getRuleStartPort());
ruleData.setEndPort(vsg.getRuleEndPort());
}
if (vsg.getRuleAllowedNetworkId() != null) {
List<SecurityGroupJoinVO> sgs = this.searchByIds(vsg.getRuleAllowedNetworkId());
if (sgs != null && sgs.size() > 0) {
SecurityGroupJoinVO sg = sgs.get(0);
ruleData.setSecurityGroupName(sg.getName());
ruleData.setAccountName(sg.getAccountName());
}
} else {
ruleData.setCidr(vsg.getRuleAllowedSourceIpCidr());
}
// add the tags to the rule data
List<ResourceTagJoinVO> tags = _resourceTagJoinDao.listBy(vsg.getRuleUuid(), ResourceTag.ResourceObjectType.SecurityGroupRule);
Set<ResourceTagResponse> tagResponse = new HashSet<ResourceTagResponse>();
for (ResourceTagJoinVO tag : tags) {
tagResponse.add(ApiDBUtils.newResourceTagResponse(tag, false));
}
// add the tags to the rule data
ruleData.setTags(tagResponse);
if (vsg.getRuleType() == SecurityRuleType.IngressRule) {
ruleData.setObjectName("ingressrule");
vsgData.addSecurityGroupIngressRule(ruleData);
} else {
ruleData.setObjectName("egressrule");
vsgData.addSecurityGroupEgressRule(ruleData);
}
}
// update tag information
Long tag_id = vsg.getTagId();
if (tag_id != null && tag_id.longValue() > 0) {
ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
if (vtag != null) {
vsgData.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
}
}
return vsgData;
}
use of org.apache.cloudstack.api.response.ResourceTagResponse in project cloudstack by apache.
the class SecurityGroupJoinDaoImpl method newSecurityGroupResponse.
@Override
public SecurityGroupResponse newSecurityGroupResponse(SecurityGroupJoinVO vsg, Account caller) {
SecurityGroupResponse sgResponse = new SecurityGroupResponse();
sgResponse.setId(vsg.getUuid());
sgResponse.setName(vsg.getName());
sgResponse.setDescription(vsg.getDescription());
ApiResponseHelper.populateOwner(sgResponse, vsg);
Long rule_id = vsg.getRuleId();
if (rule_id != null && rule_id.longValue() > 0) {
SecurityGroupRuleResponse ruleData = new SecurityGroupRuleResponse();
ruleData.setRuleId(vsg.getRuleUuid());
ruleData.setProtocol(vsg.getRuleProtocol());
if ("icmp".equalsIgnoreCase(vsg.getRuleProtocol())) {
ruleData.setIcmpType(vsg.getRuleStartPort());
ruleData.setIcmpCode(vsg.getRuleEndPort());
} else {
ruleData.setStartPort(vsg.getRuleStartPort());
ruleData.setEndPort(vsg.getRuleEndPort());
}
if (vsg.getRuleAllowedNetworkId() != null) {
List<SecurityGroupJoinVO> sgs = this.searchByIds(vsg.getRuleAllowedNetworkId());
if (sgs != null && sgs.size() > 0) {
SecurityGroupJoinVO sg = sgs.get(0);
ruleData.setSecurityGroupName(sg.getName());
ruleData.setAccountName(sg.getAccountName());
}
} else {
ruleData.setCidr(vsg.getRuleAllowedSourceIpCidr());
}
// list the tags by rule uuid
List<ResourceTagJoinVO> tags = _resourceTagJoinDao.listBy(vsg.getRuleUuid(), ResourceTag.ResourceObjectType.SecurityGroupRule);
Set<ResourceTagResponse> tagResponse = new HashSet<ResourceTagResponse>();
for (ResourceTagJoinVO tag : tags) {
tagResponse.add(ApiDBUtils.newResourceTagResponse(tag, false));
}
// add the tags to the rule data
ruleData.setTags(tagResponse);
if (vsg.getRuleType() == SecurityRuleType.IngressRule) {
ruleData.setObjectName("ingressrule");
sgResponse.addSecurityGroupIngressRule(ruleData);
} else {
ruleData.setObjectName("egressrule");
sgResponse.addSecurityGroupEgressRule(ruleData);
}
}
List<SecurityGroupVMMapVO> securityGroupVmMap = _securityGroupVMMapDao.listBySecurityGroup(vsg.getId());
s_logger.debug("newSecurityGroupResponse() -> virtualmachine count: " + securityGroupVmMap.size());
sgResponse.setVirtualMachineCount(securityGroupVmMap.size());
for (SecurityGroupVMMapVO securityGroupVMMapVO : securityGroupVmMap) {
final UserVmVO userVmVO = _userVmDao.findById(securityGroupVMMapVO.getInstanceId());
if (userVmVO != null) {
sgResponse.addVirtualMachineId(userVmVO.getUuid());
}
}
// update tag information
Long tag_id = vsg.getTagId();
if (tag_id != null && tag_id.longValue() > 0) {
ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
if (vtag != null) {
sgResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
}
}
// set async job
if (vsg.getJobId() != null) {
sgResponse.setJobId(vsg.getJobUuid());
sgResponse.setJobStatus(vsg.getJobStatus());
}
sgResponse.setObjectName("securitygroup");
return sgResponse;
}
use of org.apache.cloudstack.api.response.ResourceTagResponse in project cloudstack by apache.
the class ApiResponseHelper method createIPAddressResponse.
@Override
public IPAddressResponse createIPAddressResponse(ResponseView view, IpAddress ipAddr) {
VlanVO vlan = ApiDBUtils.findVlanById(ipAddr.getVlanId());
boolean forVirtualNetworks = vlan.getVlanType().equals(VlanType.VirtualNetwork);
long zoneId = ipAddr.getDataCenterId();
IPAddressResponse ipResponse = new IPAddressResponse();
ipResponse.setId(ipAddr.getUuid());
ipResponse.setIpAddress(ipAddr.getAddress().toString());
if (ipAddr.getAllocatedTime() != null) {
ipResponse.setAllocated(ipAddr.getAllocatedTime());
}
DataCenter zone = ApiDBUtils.findZoneById(ipAddr.getDataCenterId());
if (zone != null) {
ipResponse.setZoneId(zone.getUuid());
ipResponse.setZoneName(zone.getName());
}
ipResponse.setSourceNat(ipAddr.isSourceNat());
ipResponse.setIsSystem(ipAddr.getSystem());
// get account information
if (ipAddr.getAllocatedToAccountId() != null) {
populateOwner(ipResponse, ipAddr);
}
ipResponse.setForVirtualNetwork(forVirtualNetworks);
ipResponse.setStaticNat(ipAddr.isOneToOneNat());
if (ipAddr.getAssociatedWithVmId() != null) {
UserVm vm = ApiDBUtils.findUserVmById(ipAddr.getAssociatedWithVmId());
if (vm != null) {
ipResponse.setVirtualMachineId(vm.getUuid());
ipResponse.setVirtualMachineName(vm.getHostName());
if (vm.getDisplayName() != null) {
ipResponse.setVirtualMachineDisplayName(vm.getDisplayName());
} else {
ipResponse.setVirtualMachineDisplayName(vm.getHostName());
}
}
}
if (ipAddr.getVmIp() != null) {
ipResponse.setVirtualMachineIp(ipAddr.getVmIp());
}
if (ipAddr.getAssociatedWithNetworkId() != null) {
Network ntwk = ApiDBUtils.findNetworkById(ipAddr.getAssociatedWithNetworkId());
if (ntwk != null) {
ipResponse.setAssociatedNetworkId(ntwk.getUuid());
ipResponse.setAssociatedNetworkName(ntwk.getName());
}
}
if (ipAddr.getVpcId() != null) {
Vpc vpc = ApiDBUtils.findVpcById(ipAddr.getVpcId());
if (vpc != null) {
ipResponse.setVpcId(vpc.getUuid());
ipResponse.setVpcName(vpc.getName());
}
}
// Network id the ip is associated with (if associated networkId is
// null, try to get this information from vlan)
Long vlanNetworkId = ApiDBUtils.getVlanNetworkId(ipAddr.getVlanId());
// Network id the ip belongs to
Long networkId;
if (vlanNetworkId != null) {
networkId = vlanNetworkId;
} else {
networkId = ApiDBUtils.getPublicNetworkIdByZone(zoneId);
}
if (networkId != null) {
NetworkVO nw = ApiDBUtils.findNetworkById(networkId);
if (nw != null) {
ipResponse.setNetworkId(nw.getUuid());
ipResponse.setNetworkName(nw.getName());
}
}
ipResponse.setState(ipAddr.getState().toString());
if (ipAddr.getPhysicalNetworkId() != null) {
PhysicalNetworkVO pnw = ApiDBUtils.findPhysicalNetworkById(ipAddr.getPhysicalNetworkId());
if (pnw != null) {
ipResponse.setPhysicalNetworkId(pnw.getUuid());
}
}
// show vm info for shared networks
showVmInfoForSharedNetworks(forVirtualNetworks, ipAddr, ipResponse);
// show this info to full view only
if (view == ResponseView.Full) {
VlanVO vl = ApiDBUtils.findVlanById(ipAddr.getVlanId());
if (vl != null) {
ipResponse.setVlanId(vl.getUuid());
ipResponse.setVlanName(vl.getVlanTag());
}
}
if (ipAddr.getSystem()) {
if (ipAddr.isOneToOneNat()) {
ipResponse.setPurpose(IpAddress.Purpose.StaticNat.toString());
} else {
ipResponse.setPurpose(IpAddress.Purpose.Lb.toString());
}
}
ipResponse.setForDisplay(ipAddr.isDisplay());
ipResponse.setPortable(ipAddr.isPortable());
// set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.PublicIpAddress, ipAddr.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
}
ipResponse.setTags(tagResponses);
ipResponse.setHasAnnotation(annotationDao.hasAnnotations(ipAddr.getUuid(), AnnotationService.EntityType.PUBLIC_IP_ADDRESS.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
ipResponse.setObjectName("ipaddress");
return ipResponse;
}
Aggregations