return clusterResponse;
}
@Override
public FirewallRuleResponse createPortForwardingRuleResponse(PortForwardingRule fwRule) {
FirewallRuleResponse response = new FirewallRuleResponse();
response.setId(fwRule.getId());
response.setPrivateStartPort(Integer.toString(fwRule.getDestinationPortStart()));
response.setPrivateEndPort(Integer.toString(fwRule.getDestinationPortEnd()));
response.setProtocol(fwRule.getProtocol());
response.setPublicStartPort(Integer.toString(fwRule.getSourcePortStart()));
response.setPublicEndPort(Integer.toString(fwRule.getSourcePortEnd()));
List<String> cidrs = ApiDBUtils.findFirewallSourceCidrs(fwRule.getId());
response.setCidrList(StringUtils.join(cidrs, ","));
IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId());
response.setPublicIpAddressId(ip.getId());
response.setPublicIpAddress(ip.getAddress().addr());
if (ip != null && fwRule.getDestinationIpAddress() != null) {
UserVm vm = ApiDBUtils.findUserVmById(fwRule.getVirtualMachineId());
if (vm != null) {
response.setVirtualMachineId(vm.getId());
response.setVirtualMachineName(vm.getHostName());
if (vm.getDisplayName() != null) {
response.setVirtualMachineDisplayName(vm.getDisplayName());
} else {
response.setVirtualMachineDisplayName(vm.getHostName());
}
}
}
FirewallRule.State state = fwRule.getState();
String stateToSet = state.toString();
if (state.equals(FirewallRule.State.Revoke)) {
stateToSet = "Deleting";
}
//set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.PortForwardingRule, fwRule.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
tagResponses.add(tagResponse);
}
response.setTags(tagResponses);
response.setState(stateToSet);
response.setObjectName("portforwardingrule");
return response;
}