@Override
public DomainRouterResponse createDomainRouterResponse(VirtualRouter router) {
Account caller = UserContext.current().getCaller();
Map<Long, ServiceOffering> serviceOfferings = new HashMap<Long, ServiceOffering>();
DomainRouterResponse routerResponse = new DomainRouterResponse();
routerResponse.setId(router.getId());
routerResponse.setZoneId(router.getDataCenterIdToDeployIn());
routerResponse.setName(router.getHostName());
routerResponse.setTemplateId(router.getTemplateId());
routerResponse.setCreated(router.getCreated());
routerResponse.setState(router.getState());
routerResponse.setIsRedundantRouter(router.getIsRedundantRouter());
routerResponse.setRedundantState(router.getRedundantState().toString());
if (caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_ADMIN) {
if (router.getHostId() != null) {
routerResponse.setHostId(router.getHostId());
routerResponse.setHostName(ApiDBUtils.findHostById(router.getHostId()).getName());
}
routerResponse.setPodId(router.getPodIdToDeployIn());
List<NicProfile> nicProfiles = ApiDBUtils.getNics(router);
List<NicResponse> nicResponses = new ArrayList<NicResponse>();
for (NicProfile singleNicProfile : nicProfiles) {
Network network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId());
//legacy code, public/control/guest nic info is kept in nics response object
if (network != null) {
if (network.getTrafficType() == TrafficType.Public) {
routerResponse.setPublicIp(singleNicProfile.getIp4Address());
routerResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
routerResponse.setPublicNetmask(singleNicProfile.getNetmask());
routerResponse.setGateway(singleNicProfile.getGateway());
routerResponse.setPublicNetworkId(singleNicProfile.getNetworkId());
} else if (network.getTrafficType() == TrafficType.Control) {
routerResponse.setLinkLocalIp(singleNicProfile.getIp4Address());
routerResponse.setLinkLocalMacAddress(singleNicProfile.getMacAddress());
routerResponse.setLinkLocalNetmask(singleNicProfile.getNetmask());
routerResponse.setLinkLocalNetworkId(singleNicProfile.getNetworkId());
} else if (network.getTrafficType() == TrafficType.Guest) {
routerResponse.setGuestIpAddress(singleNicProfile.getIp4Address());
routerResponse.setGuestMacAddress(singleNicProfile.getMacAddress());
routerResponse.setGuestNetmask(singleNicProfile.getNetmask());
routerResponse.setGuestNetworkId(singleNicProfile.getNetworkId());
routerResponse.setNetworkDomain(network.getNetworkDomain());
}
NicResponse nicResponse = new NicResponse();
nicResponse.setId(singleNicProfile.getId());
nicResponse.setIpaddress(singleNicProfile.getIp4Address());
nicResponse.setGateway(singleNicProfile.getGateway());
nicResponse.setNetmask(singleNicProfile.getNetmask());
nicResponse.setNetworkid(singleNicProfile.getNetworkId());
nicResponse.setNetworkName(network.getName());
if (singleNicProfile.getBroadCastUri() != null) {
nicResponse.setBroadcastUri(singleNicProfile.getBroadCastUri().toString());
}
if (singleNicProfile.getIsolationUri() != null) {
nicResponse.setIsolationUri(singleNicProfile.getIsolationUri().toString());
}
nicResponse.setTrafficType(network.getTrafficType().toString());
if (network.getGuestType() != null) {
nicResponse.setType(network.getGuestType().toString());
}
nicResponse.setIsDefault(singleNicProfile.isDefaultNic());
nicResponse.setObjectName("nic");
nicResponses.add(nicResponse);
}
}
routerResponse.setNics(nicResponses);
}
// Service Offering Info
ServiceOffering offering = serviceOfferings.get(router.getServiceOfferingId());
if (offering == null) {
offering = ApiDBUtils.findServiceOfferingById(router.getServiceOfferingId());
serviceOfferings.put(offering.getId(), offering);
}
routerResponse.setServiceOfferingId(offering.getId());
routerResponse.setServiceOfferingName(offering.getName());
populateOwner(routerResponse, router);
DataCenter zone = ApiDBUtils.findZoneById(router.getDataCenterIdToDeployIn());
if (zone != null) {
routerResponse.setZoneName(zone.getName());
routerResponse.setDns1(zone.getDns1());
routerResponse.setDns2(zone.getDns2());
}
routerResponse.setVpcId(router.getVpcId());
routerResponse.setObjectName("domainrouter");
return routerResponse;
}