mirror of https://github.com/apache/cloudstack.git
fix logger
This commit is contained in:
parent
27599d85fc
commit
072c97d457
|
|
@ -49,7 +49,8 @@ import org.apache.cloudstack.agent.api.DeleteNsxTier1GatewayCommand;
|
|||
import org.apache.cloudstack.service.NsxApiClient;
|
||||
import org.apache.cloudstack.utils.NsxControllerUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -59,7 +60,7 @@ import java.util.Objects;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public class NsxResource implements ServerResource {
|
||||
private static final Logger LOGGER = Logger.getLogger(NsxResource.class);
|
||||
protected Logger logger = LogManager.getLogger(getClass());
|
||||
private static final String DHCP_RELAY_CONFIGS_PATH_PREFIX = "/infra/dhcp-relay-configs";
|
||||
|
||||
private String name;
|
||||
|
|
@ -243,7 +244,7 @@ public class NsxResource implements ServerResource {
|
|||
nsxApiClient.createTier1NatRule(tier1GatewayName, natId, natRuleId, action, translatedIpAddress);
|
||||
} catch (CloudRuntimeException e) {
|
||||
String msg = String.format("Error creating the NAT rule with ID %s on Tier1 Gateway %s: %s", natRuleId, tier1GatewayName, e.getMessage());
|
||||
LOGGER.error(msg, e);
|
||||
logger.error(msg, e);
|
||||
return new NsxAnswer(cmd, e);
|
||||
}
|
||||
return new NsxAnswer(cmd, true, "");
|
||||
|
|
@ -263,13 +264,13 @@ public class NsxResource implements ServerResource {
|
|||
|
||||
String msg = String.format("Creating DHCP relay config with name %s on network %s of VPC %s",
|
||||
dhcpRelayConfigName, networkName, vpcName);
|
||||
LOGGER.debug(msg);
|
||||
logger.debug(msg);
|
||||
|
||||
try {
|
||||
nsxApiClient.createDhcpRelayConfig(dhcpRelayConfigName, addresses);
|
||||
} catch (CloudRuntimeException e) {
|
||||
msg = String.format("Error creating the DHCP relay config with name %s: %s", dhcpRelayConfigName, e.getMessage());
|
||||
LOGGER.error(msg, e);
|
||||
logger.error(msg, e);
|
||||
return new NsxAnswer(cmd, e);
|
||||
}
|
||||
|
||||
|
|
@ -281,7 +282,7 @@ public class NsxResource implements ServerResource {
|
|||
nsxApiClient.updateSegment(segmentName, segment);
|
||||
} catch (CloudRuntimeException e) {
|
||||
msg = String.format("Error adding the DHCP relay config with name %s to the segment %s: %s", dhcpRelayConfigName, segmentName, e.getMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
return new NsxAnswer(cmd, e);
|
||||
}
|
||||
|
||||
|
|
@ -301,7 +302,7 @@ public class NsxResource implements ServerResource {
|
|||
} catch (CloudRuntimeException e) {
|
||||
String msg = String.format("Cannot create tier 1 gateway %s (%s: %s): %s", tier1GatewayName,
|
||||
(cmd.isResourceVpc() ? "VPC" : "NETWORK"), cmd.getNetworkResourceName(), e.getMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
return new NsxAnswer(cmd, e);
|
||||
}
|
||||
}
|
||||
|
|
@ -325,13 +326,13 @@ public class NsxResource implements ServerResource {
|
|||
TransportZoneListResult transportZoneListResult = nsxApiClient.getTransportZones();
|
||||
if (CollectionUtils.isEmpty(transportZoneListResult.getResults())) {
|
||||
String errorMsg = String.format("Failed to create network: %s as no transport zones were found in the linked NSX infrastructure", cmd.getNetworkName());
|
||||
LOGGER.error(errorMsg);
|
||||
logger.error(errorMsg);
|
||||
return new NsxAnswer(cmd, new CloudRuntimeException(errorMsg));
|
||||
}
|
||||
List<TransportZone> transportZones = transportZoneListResult.getResults().stream().filter(tz -> tz.getDisplayName().equals(transportZone)).collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(transportZones)) {
|
||||
String errorMsg = String.format("Failed to create network: %s as no transport zone of name %s was found in the linked NSX infrastructure", cmd.getNetworkName(), transportZone);
|
||||
LOGGER.error(errorMsg);
|
||||
logger.error(errorMsg);
|
||||
return new NsxAnswer(cmd, new CloudRuntimeException(errorMsg));
|
||||
}
|
||||
|
||||
|
|
@ -345,7 +346,7 @@ public class NsxResource implements ServerResource {
|
|||
nsxApiClient.createSegment(segmentName, tier1GatewayName, gatewayAddress, enforcementPointPath, transportZones);
|
||||
nsxApiClient.createGroupForSegment(segmentName);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(String.format("Failed to create network: %s", cmd.getNetworkName()));
|
||||
logger.error(String.format("Failed to create network: %s", cmd.getNetworkName()));
|
||||
return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage()));
|
||||
}
|
||||
return new NsxAnswer(cmd, true, null);
|
||||
|
|
@ -357,7 +358,7 @@ public class NsxResource implements ServerResource {
|
|||
try {
|
||||
nsxApiClient.deleteSegment(cmd.getZoneId(), cmd.getDomainId(), cmd.getAccountId(), cmd.getVpcId(), cmd.getNetworkId(), segmentName);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(String.format("Failed to delete NSX segment %s: %s", segmentName, e.getMessage()));
|
||||
logger.error(String.format("Failed to delete NSX segment %s: %s", segmentName, e.getMessage()));
|
||||
return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage()));
|
||||
}
|
||||
return new NsxAnswer(cmd, true, null);
|
||||
|
|
@ -371,7 +372,7 @@ public class NsxResource implements ServerResource {
|
|||
try {
|
||||
nsxApiClient.createStaticNatRule(cmd.getNetworkResourceName(), tier1GatewayName, staticNatRuleName, cmd.getPublicIp(), cmd.getVmIp());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(String.format("Failed to add NSX static NAT rule %s for network: %s", staticNatRuleName, cmd.getNetworkResourceName()));
|
||||
logger.error(String.format("Failed to add NSX static NAT rule %s for network: %s", staticNatRuleName, cmd.getNetworkResourceName()));
|
||||
return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage()));
|
||||
}
|
||||
return new NsxAnswer(cmd, true, null);
|
||||
|
|
@ -390,7 +391,7 @@ public class NsxResource implements ServerResource {
|
|||
nsxApiClient.createPortForwardingRule(ruleName, tier1GatewayName, cmd.getNetworkResourceName(), cmd.getPublicIp(),
|
||||
cmd.getVmIp(), cmd.getPublicPort(), service);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(String.format("Failed to add NSX port forward rule %s for network: %s", ruleName, cmd.getNetworkResourceName()));
|
||||
logger.error(String.format("Failed to add NSX port forward rule %s for network: %s", ruleName, cmd.getNetworkResourceName()));
|
||||
return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage()));
|
||||
}
|
||||
return new NsxAnswer(cmd, true, null);
|
||||
|
|
@ -411,7 +412,7 @@ public class NsxResource implements ServerResource {
|
|||
nsxApiClient.deleteNatRule(cmd.getService(), cmd.getPrivatePort(), cmd.getProtocol(),
|
||||
cmd.getNetworkResourceName(), tier1GatewayName, ruleName);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(String.format("Failed to add NSX static NAT rule %s for network: %s", ruleName, cmd.getNetworkResourceName()));
|
||||
logger.error(String.format("Failed to add NSX static NAT rule %s for network: %s", ruleName, cmd.getNetworkResourceName()));
|
||||
return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage()));
|
||||
}
|
||||
return new NsxAnswer(cmd, true, null);
|
||||
|
|
@ -425,7 +426,7 @@ public class NsxResource implements ServerResource {
|
|||
nsxApiClient.createAndAddNsxLbVirtualServer(tier1GatewayName, cmd.getLbId(), cmd.getPublicIp(), cmd.getPublicPort(),
|
||||
cmd.getMemberList(), cmd.getAlgorithm(), cmd.getProtocol(), cmd.getPrivatePort());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(String.format("Failed to add NSX load balancer rule %s for network: %s", ruleName, cmd.getNetworkResourceName()));
|
||||
logger.error(String.format("Failed to add NSX load balancer rule %s for network: %s", ruleName, cmd.getNetworkResourceName()));
|
||||
return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage()));
|
||||
}
|
||||
return new NsxAnswer(cmd, true, null);
|
||||
|
|
@ -438,7 +439,7 @@ public class NsxResource implements ServerResource {
|
|||
try {
|
||||
nsxApiClient.deleteNsxLbResources(tier1GatewayName, cmd.getLbId());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(String.format("Failed to add NSX load balancer rule %s for network: %s", ruleName, cmd.getNetworkResourceName()));
|
||||
logger.error(String.format("Failed to add NSX load balancer rule %s for network: %s", ruleName, cmd.getNetworkResourceName()));
|
||||
return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage()));
|
||||
}
|
||||
return new NsxAnswer(cmd, true, null);
|
||||
|
|
@ -451,7 +452,7 @@ public class NsxResource implements ServerResource {
|
|||
try {
|
||||
nsxApiClient.createSegmentDistributedFirewall(segmentName, rules);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(String.format("Failed to create NSX distributed firewall %s: %s", segmentName, e.getMessage()), e);
|
||||
logger.error(String.format("Failed to create NSX distributed firewall %s: %s", segmentName, e.getMessage()), e);
|
||||
return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage()));
|
||||
}
|
||||
return new NsxAnswer(cmd, true, null);
|
||||
|
|
@ -464,7 +465,7 @@ public class NsxResource implements ServerResource {
|
|||
try {
|
||||
nsxApiClient.deleteDistributedFirewallRules(segmentName, rules);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(String.format("Failed to delete NSX distributed firewall %s: %s", segmentName, e.getMessage()), e);
|
||||
logger.error(String.format("Failed to delete NSX distributed firewall %s: %s", segmentName, e.getMessage()), e);
|
||||
return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage()));
|
||||
}
|
||||
return new NsxAnswer(cmd, true, null);
|
||||
|
|
|
|||
|
|
@ -82,7 +82,8 @@ import org.apache.cloudstack.resource.NsxLoadBalancerMember;
|
|||
import org.apache.cloudstack.resource.NsxNetworkRule;
|
||||
import org.apache.cloudstack.utils.NsxControllerUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -108,7 +109,7 @@ public class NsxApiClient {
|
|||
protected Function<Class<? extends Service>, Service> nsxService;
|
||||
|
||||
public static final int RESPONSE_TIMEOUT_SECONDS = 60;
|
||||
private static final Logger LOGGER = Logger.getLogger(NsxApiClient.class);
|
||||
protected Logger logger = LogManager.getLogger(getClass());
|
||||
|
||||
// Constants
|
||||
private static final String TIER_1_RESOURCE_TYPE = "Tier1";
|
||||
|
|
@ -219,7 +220,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Error creating the DHCP relay config with name %s: %s", dhcpRelayConfigName, ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(ae.getErrorMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -231,7 +232,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Error obtaining the segment with name %s: %s", segmentName, ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(ae.getErrorMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -243,7 +244,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Error updating the segment with name %s: %s", segmentName, ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(ae.getErrorMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -253,7 +254,7 @@ public class NsxApiClient {
|
|||
Tier1s tier1service = (Tier1s) nsxService.apply(Tier1s.class);
|
||||
return tier1service.get(tier1GatewayId);
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(String.format("NSX Tier-1 gateway with name: %s not found", tier1GatewayId));
|
||||
logger.debug(String.format("NSX Tier-1 gateway with name: %s not found", tier1GatewayId));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -298,7 +299,7 @@ public class NsxApiClient {
|
|||
String tier0GatewayPath = TIER_0_GATEWAY_PATH_PREFIX + tier0Gateway;
|
||||
Tier1 tier1 = getTier1Gateway(name);
|
||||
if (tier1 != null) {
|
||||
LOGGER.info(String.format("VPC network with name %s exists in NSX zone", name));
|
||||
logger.info(String.format("VPC network with name %s exists in NSX zone", name));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -321,7 +322,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Error creating tier 1 gateway %s: %s", name, ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -330,7 +331,7 @@ public class NsxApiClient {
|
|||
com.vmware.nsx_policy.infra.tier_1s.LocaleServices localeService = (com.vmware.nsx_policy.infra.tier_1s.LocaleServices)
|
||||
nsxService.apply(com.vmware.nsx_policy.infra.tier_1s.LocaleServices.class);
|
||||
if (getTier1Gateway(tier1Id) == null) {
|
||||
LOGGER.warn(String.format("The Tier 1 Gateway %s does not exist, cannot be removed", tier1Id));
|
||||
logger.warn(String.format("The Tier 1 Gateway %s does not exist, cannot be removed", tier1Id));
|
||||
return;
|
||||
}
|
||||
removeTier1GatewayNatRules(tier1Id);
|
||||
|
|
@ -345,10 +346,10 @@ public class NsxApiClient {
|
|||
PolicyNatRuleListResult result = natRulesService.list(tier1Id, natId, null, false, null, null, null, null);
|
||||
List<PolicyNatRule> natRules = result.getResults();
|
||||
if (CollectionUtils.isEmpty(natRules)) {
|
||||
LOGGER.debug(String.format("Didn't find any NAT rule to remove on the Tier 1 Gateway %s", tier1Id));
|
||||
logger.debug(String.format("Didn't find any NAT rule to remove on the Tier 1 Gateway %s", tier1Id));
|
||||
} else {
|
||||
for (PolicyNatRule natRule : natRules) {
|
||||
LOGGER.debug(String.format("Removing NAT rule %s from Tier 1 Gateway %s", natRule.getId(), tier1Id));
|
||||
logger.debug(String.format("Removing NAT rule %s from Tier 1 Gateway %s", natRule.getId(), tier1Id));
|
||||
natRulesService.delete(tier1Id, natId, natRule.getId());
|
||||
}
|
||||
}
|
||||
|
|
@ -359,7 +360,7 @@ public class NsxApiClient {
|
|||
SiteListResult sites = getSites();
|
||||
if (CollectionUtils.isEmpty(sites.getResults())) {
|
||||
String errorMsg = "No sites are found in the linked NSX infrastructure";
|
||||
LOGGER.error(errorMsg);
|
||||
logger.error(errorMsg);
|
||||
throw new CloudRuntimeException(errorMsg);
|
||||
}
|
||||
return sites.getResults().get(0).getId();
|
||||
|
|
@ -378,7 +379,7 @@ public class NsxApiClient {
|
|||
EnforcementPointListResult epList = getEnforcementPoints(siteId);
|
||||
if (CollectionUtils.isEmpty(epList.getResults())) {
|
||||
String errorMsg = String.format("No enforcement points are found in the linked NSX infrastructure for site ID %s", siteId);
|
||||
LOGGER.error(errorMsg);
|
||||
logger.error(errorMsg);
|
||||
throw new CloudRuntimeException(errorMsg);
|
||||
}
|
||||
return epList.getResults().get(0).getPath();
|
||||
|
|
@ -422,7 +423,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Error creating segment %s: %s", segmentName, ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -437,28 +438,28 @@ public class NsxApiClient {
|
|||
removeSegment(segmentName);
|
||||
DhcpRelayConfigs dhcpRelayConfig = (DhcpRelayConfigs) nsxService.apply(DhcpRelayConfigs.class);
|
||||
String dhcpRelayConfigId = NsxControllerUtils.getNsxDhcpRelayConfigId(zoneId, domainId, accountId, vpcId, networkId);
|
||||
LOGGER.debug(String.format("Removing the DHCP relay config with ID %s", dhcpRelayConfigId));
|
||||
logger.debug(String.format("Removing the DHCP relay config with ID %s", dhcpRelayConfigId));
|
||||
dhcpRelayConfig.delete(dhcpRelayConfigId);
|
||||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Error deleting segment %s: %s", segmentName, ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected void removeSegment(String segmentName) {
|
||||
LOGGER.debug(String.format("Removing the segment with ID %s", segmentName));
|
||||
logger.debug(String.format("Removing the segment with ID %s", segmentName));
|
||||
Segments segmentService = (Segments) nsxService.apply(Segments.class);
|
||||
String errMsg = String.format("The segment with ID %s is not found, skipping removal", segmentName);
|
||||
try {
|
||||
Segment segment = segmentService.get(segmentName);
|
||||
if (segment == null) {
|
||||
LOGGER.warn(errMsg);
|
||||
logger.warn(errMsg);
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn(errMsg);
|
||||
logger.warn(errMsg);
|
||||
return;
|
||||
}
|
||||
String siteId = getDefaultSiteId();
|
||||
|
|
@ -467,14 +468,14 @@ public class NsxApiClient {
|
|||
PolicyGroupMembersListResult segmentPortsList = getSegmentPortList(segmentPortsService, segmentName, enforcementPointPath);
|
||||
Long portCount = segmentPortsList.getResultCount();
|
||||
portCount = retrySegmentDeletion(segmentPortsService, portCount, segmentName, enforcementPointPath);
|
||||
LOGGER.info("Port count: " + portCount);
|
||||
logger.info("Port count: " + portCount);
|
||||
if (portCount == 0L) {
|
||||
LOGGER.debug(String.format("Removing the segment with ID %s", segmentName));
|
||||
logger.debug(String.format("Removing the segment with ID %s", segmentName));
|
||||
removeGroupForSegment(segmentName);
|
||||
segmentService.delete(segmentName);
|
||||
} else {
|
||||
String msg = String.format("Cannot remove the NSX segment %s because there are still %s port group(s) attached to it", segmentName, portCount);
|
||||
LOGGER.debug(msg);
|
||||
logger.debug(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -489,7 +490,7 @@ public class NsxApiClient {
|
|||
int count = 1;
|
||||
do {
|
||||
try {
|
||||
LOGGER.info("Waiting for all port groups to be unlinked from the segment - Attempt: " + count++ + " Waiting for 5 secs");
|
||||
logger.info("Waiting for all port groups to be unlinked from the segment - Attempt: " + count++ + " Waiting for 5 secs");
|
||||
Thread.sleep(5000);
|
||||
portCount = getSegmentPortList(segmentPortsService, segmentName, enforcementPointPath).getResultCount();
|
||||
retries--;
|
||||
|
|
@ -514,13 +515,13 @@ public class NsxApiClient {
|
|||
.setEnabled(true)
|
||||
.build();
|
||||
|
||||
LOGGER.debug(String.format("Creating NSX static NAT rule %s for tier-1 gateway %s (VPC: %s)", ruleName, tier1GatewayName, vpcName));
|
||||
logger.debug(String.format("Creating NSX static NAT rule %s for tier-1 gateway %s (VPC: %s)", ruleName, tier1GatewayName, vpcName));
|
||||
natService.patch(tier1GatewayName, NatId.USER.name(), ruleName, rule);
|
||||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Error creating NSX Static NAT rule %s for tier-1 gateway %s (VPC: %s), due to %s",
|
||||
ruleName, tier1GatewayName, vpcName, ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -528,7 +529,7 @@ public class NsxApiClient {
|
|||
public void deleteNatRule(Network.Service service, String privatePort, String protocol, String networkName, String tier1GatewayName, String ruleName) {
|
||||
try {
|
||||
NatRules natService = (NatRules) nsxService.apply(NatRules.class);
|
||||
LOGGER.debug(String.format("Deleting NSX static NAT rule %s for tier-1 gateway %s (network: %s)", ruleName, tier1GatewayName, networkName));
|
||||
logger.debug(String.format("Deleting NSX static NAT rule %s for tier-1 gateway %s (network: %s)", ruleName, tier1GatewayName, networkName));
|
||||
// delete NAT rule
|
||||
natService.delete(tier1GatewayName, NatId.USER.name(), ruleName);
|
||||
if (service == Network.Service.PortForwarding) {
|
||||
|
|
@ -541,7 +542,7 @@ public class NsxApiClient {
|
|||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to delete NSX Static NAT rule %s for tier-1 gateway %s (VPC: %s), due to %s",
|
||||
ruleName, tier1GatewayName, networkName, ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -550,7 +551,7 @@ public class NsxApiClient {
|
|||
String vmIp, String publicPort, String service) {
|
||||
try {
|
||||
NatRules natService = (NatRules) nsxService.apply(NatRules.class);
|
||||
LOGGER.debug(String.format("Creating NSX Port-Forwarding NAT %s for network %s", ruleName, networkName));
|
||||
logger.debug(String.format("Creating NSX Port-Forwarding NAT %s for network %s", ruleName, networkName));
|
||||
PolicyNatRule rule = new PolicyNatRule.Builder()
|
||||
.setId(ruleName)
|
||||
.setDisplayName(ruleName)
|
||||
|
|
@ -567,7 +568,7 @@ public class NsxApiClient {
|
|||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to delete NSX Port-forward rule %s for network: %s, due to %s",
|
||||
ruleName, networkName, ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -586,7 +587,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to create NSX LB pool members, due to: %s", ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -610,7 +611,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to create NSX LB server pool, due to: %s", ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -660,7 +661,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to create NSX load balancer, due to: %s", ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -688,7 +689,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to create and add NSX virtual server to the Load Balancer, due to: %s", ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -724,7 +725,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to delete NSX Load Balancer resources, due to: %s", ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -742,7 +743,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to get NSX LB server pool, due to: %s", ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -767,7 +768,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to get NSX LB server pool, due to: %s", ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -782,7 +783,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to list NSX LB App profiles, due to: %s", ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -816,7 +817,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to list NSX infra service, due to: %s", ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -866,7 +867,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to create NSX infra service, due to: %s", ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -888,7 +889,7 @@ public class NsxApiClient {
|
|||
* Create a Group for the Segment on the Inventory, with the same name as the segment and being the segment the only member of the group
|
||||
*/
|
||||
public void createGroupForSegment(String segmentName) {
|
||||
LOGGER.info(String.format("Creating Group for Segment %s", segmentName));
|
||||
logger.info(String.format("Creating Group for Segment %s", segmentName));
|
||||
|
||||
PathExpression pathExpression = new PathExpression();
|
||||
List<String> paths = List.of(String.format("%s/%s", SEGMENTS_PATH, segmentName));
|
||||
|
|
@ -907,7 +908,7 @@ public class NsxApiClient {
|
|||
* Remove Segment Group from the Inventory
|
||||
*/
|
||||
private void removeGroupForSegment(String segmentName) {
|
||||
LOGGER.info(String.format("Removing Group for Segment %s", segmentName));
|
||||
logger.info(String.format("Removing Group for Segment %s", segmentName));
|
||||
Groups service = (Groups) nsxService.apply(Groups.class);
|
||||
service.delete(DEFAULT_DOMAIN, segmentName, true, false);
|
||||
}
|
||||
|
|
@ -919,7 +920,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to remove NSX distributed firewall policy for segment %s, due to: %s", segmentName, ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -943,7 +944,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to create NSX distributed firewall policy for segment %s, due to: %s", segmentName, ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -1010,7 +1011,7 @@ public class NsxApiClient {
|
|||
return source ? segmentGroup : egressSource;
|
||||
}
|
||||
String err = String.format("Unsupported traffic type %s", trafficType);
|
||||
LOGGER.error(err);
|
||||
logger.error(err);
|
||||
throw new CloudRuntimeException(err);
|
||||
}
|
||||
|
||||
|
|
@ -1023,7 +1024,7 @@ public class NsxApiClient {
|
|||
} catch (Error error) {
|
||||
ApiError ae = error.getData()._convertTo(ApiError.class);
|
||||
String msg = String.format("Failed to list NSX groups, due to: %s", ae.getErrorMessage());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,8 @@ import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
|
|||
import org.apache.cloudstack.resource.NsxLoadBalancerMember;
|
||||
import org.apache.cloudstack.resource.NsxNetworkRule;
|
||||
import org.apache.cloudstack.resource.NsxOpObject;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -159,7 +160,7 @@ public class NsxElement extends AdapterBase implements DhcpServiceProvider, Dns
|
|||
@Inject
|
||||
PhysicalNetworkServiceProviderDao pNtwkSvcProviderDao;
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(NsxElement.class);
|
||||
protected Logger logger = LogManager.getLogger(getClass());
|
||||
|
||||
private final Map<Network.Service, Map<Network.Capability, String>> capabilities = initCapabilities();
|
||||
|
||||
|
|
@ -286,7 +287,7 @@ public class NsxElement extends AdapterBase implements DhcpServiceProvider, Dns
|
|||
DomainVO domain = domainDao.findById(account.getDomainId());
|
||||
if (Objects.isNull(zone)) {
|
||||
String msg = String.format("Cannot find zone with ID %s", network.getDataCenterId());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
return nsxService.deleteNetwork(zone.getId(), account.getId(), domain.getId(), networkVO);
|
||||
|
|
@ -352,7 +353,7 @@ public class NsxElement extends AdapterBase implements DhcpServiceProvider, Dns
|
|||
DomainVO domain = domainDao.findById(account.getDomainId());
|
||||
if (Objects.isNull(domain)) {
|
||||
String msg = String.format("Unable to find domain with id: %s", account.getDomainId());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
return domain;
|
||||
|
|
@ -479,11 +480,11 @@ public class NsxElement extends AdapterBase implements DhcpServiceProvider, Dns
|
|||
}
|
||||
|
||||
protected boolean canHandle(Network network, Network.Service service) {
|
||||
LOGGER.debug("Checking if Nsx Element can handle service " + service.getName() + " on network "
|
||||
logger.debug("Checking if Nsx Element can handle service " + service.getName() + " on network "
|
||||
+ network.getDisplayText());
|
||||
|
||||
if (!networkModel.isProviderForNetwork(getProvider(), network.getId())) {
|
||||
LOGGER.debug("Nsx Element is not a provider for network " + network.getDisplayText());
|
||||
logger.debug("Nsx Element is not a provider for network " + network.getDisplayText());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -722,7 +723,7 @@ public class NsxElement extends AdapterBase implements DhcpServiceProvider, Dns
|
|||
if (!nsxDelNetworkRules.isEmpty()) {
|
||||
success = nsxService.deleteFirewallRules(network, nsxDelNetworkRules);
|
||||
if (!success) {
|
||||
LOGGER.warn("Not all firewall rules were successfully deleted");
|
||||
logger.warn("Not all firewall rules were successfully deleted");
|
||||
}
|
||||
}
|
||||
return success;
|
||||
|
|
@ -794,7 +795,7 @@ public class NsxElement extends AdapterBase implements DhcpServiceProvider, Dns
|
|||
if (!nsxDelNetworkRules.isEmpty()) {
|
||||
success = nsxService.deleteFirewallRules(network, nsxDelNetworkRules);
|
||||
if (!success) {
|
||||
LOGGER.warn("Not all firewall rules were successfully deleted");
|
||||
logger.warn("Not all firewall rules were successfully deleted");
|
||||
}
|
||||
}
|
||||
return success && nsxService.addFirewallRules(network, nsxAddNetworkRules);
|
||||
|
|
@ -807,7 +808,7 @@ public class NsxElement extends AdapterBase implements DhcpServiceProvider, Dns
|
|||
return NsxNetworkRule.NsxRuleAction.DROP;
|
||||
}
|
||||
String err = String.format("Unsupported action %s", action.toString());
|
||||
LOGGER.error(err);
|
||||
logger.error(err);
|
||||
throw new CloudRuntimeException(err);
|
||||
}
|
||||
|
||||
|
|
@ -847,7 +848,7 @@ public class NsxElement extends AdapterBase implements DhcpServiceProvider, Dns
|
|||
public VirtualRouterProvider addInternalLoadBalancerElement(long ntwkSvcProviderId) {
|
||||
VirtualRouterProviderVO element = vrProviderDao.findByNspIdAndType(ntwkSvcProviderId, VirtualRouterProvider.Type.Nsx);
|
||||
if (element != null) {
|
||||
LOGGER.debug("There is already an " + getName() + " with service provider id " + ntwkSvcProviderId);
|
||||
logger.debug("There is already an " + getName() + " with service provider id " + ntwkSvcProviderId);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,14 +57,15 @@ import org.apache.cloudstack.agent.api.CreateOrUpdateNsxTier1NatRuleCommand;
|
|||
import org.apache.cloudstack.utils.NsxControllerUtils;
|
||||
|
||||
import org.apache.cloudstack.utils.NsxHelper;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class NsxGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigrationResponder {
|
||||
private static final Logger LOGGER = Logger.getLogger(NsxGuestNetworkGuru.class);
|
||||
protected Logger logger = LogManager.getLogger(getClass());
|
||||
|
||||
@Inject
|
||||
NetworkOfferingServiceMapDao networkOfferingServiceMapDao;
|
||||
|
|
@ -97,7 +98,7 @@ public class NsxGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigr
|
|||
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
|
||||
|
||||
if (!canHandle(offering, dc.getNetworkType(), physnet)) {
|
||||
LOGGER.debug("Refusing to design this network");
|
||||
logger.debug("Refusing to design this network");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -206,25 +207,25 @@ public class NsxGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigr
|
|||
long zoneId = network.getDataCenterId();
|
||||
if (Objects.isNull(zone)) {
|
||||
String msg = String.format("Unable to find zone with id: %s", zoneId);
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
Account account = accountDao.findById(network.getAccountId());
|
||||
if (Objects.isNull(account)) {
|
||||
String msg = String.format("Unable to find account with id: %s", network.getAccountId());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
VpcVO vpc = _vpcDao.findById(network.getVpcId());
|
||||
if (Objects.isNull(vpc)) {
|
||||
String msg = String.format("Unable to find VPC with id: %s, allocating for network %s", network.getVpcId(), network.getName());
|
||||
LOGGER.debug(msg);
|
||||
logger.debug(msg);
|
||||
}
|
||||
|
||||
DomainVO domain = domainDao.findById(account.getDomainId());
|
||||
if (Objects.isNull(domain)) {
|
||||
String msg = String.format("Unable to find domain with id: %s", account.getDomainId());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
|
||||
|
|
@ -238,13 +239,13 @@ public class NsxGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigr
|
|||
PublicIpAddress ipAddress = networkModel.getSourceNatIpAddressForGuestNetwork(account, network);
|
||||
String translatedIp = ipAddress.getAddress().addr();
|
||||
String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(domainId, accountId, dataCenterId, resourceId, false);
|
||||
LOGGER.debug(String.format("Creating NSX NAT Rule for Tier1 GW %s for translated IP %s for Isolated network %s", tier1GatewayName, translatedIp, network.getName()));
|
||||
logger.debug(String.format("Creating NSX NAT Rule for Tier1 GW %s for translated IP %s for Isolated network %s", tier1GatewayName, translatedIp, network.getName()));
|
||||
String natRuleId = NsxControllerUtils.getNsxNatRuleId(domainId, accountId, dataCenterId, resourceId, false);
|
||||
CreateOrUpdateNsxTier1NatRuleCommand cmd = NsxHelper.createOrUpdateNsxNatRuleCommand(domainId, accountId, dataCenterId, tier1GatewayName, "SNAT", translatedIp, natRuleId);
|
||||
NsxAnswer nsxAnswer = nsxControllerUtils.sendNsxCommand(cmd, dataCenterId);
|
||||
if (!nsxAnswer.getResult()) {
|
||||
String msg = String.format("Could not create NSX NAT Rule on Tier1 Gateway %s for IP %s for Isolated network %s", tier1GatewayName, translatedIp, network.getName());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -256,7 +257,7 @@ public class NsxGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigr
|
|||
NsxAnswer answer = nsxControllerUtils.sendNsxCommand(command, zone.getId());
|
||||
if (!answer.getResult()) {
|
||||
String msg = String.format("Error creating DHCP relay config for network %s and nic %s: %s", network.getName(), nic.getName(), answer.getDetails());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
return nicProfile;
|
||||
|
|
@ -307,7 +308,7 @@ public class NsxGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigr
|
|||
DomainVO domain = domainDao.findById(account.getDomainId());
|
||||
if (Objects.isNull(domain)) {
|
||||
String msg = String.format("Unable to find domain with id: %s", account.getDomainId());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
String vpcName = null;
|
||||
|
|
@ -318,7 +319,7 @@ public class NsxGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigr
|
|||
}
|
||||
vpcName = vpc.getName();
|
||||
} else {
|
||||
LOGGER.debug(String.format("Creating a Tier 1 Gateway for the network %s before creating the NSX segment", networkVO.getName()));
|
||||
logger.debug(String.format("Creating a Tier 1 Gateway for the network %s before creating the NSX segment", networkVO.getName()));
|
||||
long networkOfferingId = networkVO.getNetworkOfferingId();
|
||||
NetworkOfferingVO networkOfferingVO = networkOfferingDao.findById(networkOfferingId);
|
||||
boolean isSourceNatSupported = !NetworkOffering.NsxMode.ROUTED.name().equals(networkOfferingVO.getNsxMode()) &&
|
||||
|
|
@ -328,7 +329,7 @@ public class NsxGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigr
|
|||
NsxAnswer nsxAnswer = nsxControllerUtils.sendNsxCommand(nsxTier1GatewayCommand, zone.getId());
|
||||
if (!nsxAnswer.getResult()) {
|
||||
String msg = String.format("Could not create a Tier 1 Gateway for network %s: %s", networkVO.getName(), nsxAnswer.getDetails());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,8 @@ import org.apache.cloudstack.api.ApiConstants;
|
|||
import org.apache.cloudstack.utils.NsxControllerUtils;
|
||||
import org.apache.cloudstack.utils.NsxHelper;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
|
@ -69,7 +70,7 @@ public class NsxPublicNetworkGuru extends PublicNetworkGuru {
|
|||
@Inject
|
||||
private NetworkOfferingDao offeringDao;
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(NsxPublicNetworkGuru.class);
|
||||
protected Logger logger = LogManager.getLogger(getClass());
|
||||
|
||||
public NsxPublicNetworkGuru() {
|
||||
super();
|
||||
|
|
@ -95,12 +96,12 @@ public class NsxPublicNetworkGuru extends PublicNetworkGuru {
|
|||
|
||||
@Override
|
||||
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
|
||||
s_logger.debug("NSX Public network guru: allocate");
|
||||
logger.debug("NSX Public network guru: allocate");
|
||||
|
||||
IPAddressVO ipAddress = _ipAddressDao.findByIp(nic.getIPv4Address());
|
||||
if (ipAddress == null) {
|
||||
String err = String.format("Cannot find the IP address %s", nic.getIPv4Address());
|
||||
s_logger.error(err);
|
||||
logger.error(err);
|
||||
throw new CloudRuntimeException(err);
|
||||
}
|
||||
Long vpcId = ipAddress.getVpcId();
|
||||
|
|
@ -108,7 +109,7 @@ public class NsxPublicNetworkGuru extends PublicNetworkGuru {
|
|||
VpcVO vpc = vpcDao.findById(vpcId);
|
||||
if (vpc == null) {
|
||||
String err = String.format("Cannot find a VPC with ID %s", vpcId);
|
||||
s_logger.error(err);
|
||||
logger.error(err);
|
||||
throw new CloudRuntimeException(err);
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +117,7 @@ public class NsxPublicNetworkGuru extends PublicNetworkGuru {
|
|||
List<IPAddressVO> ips = _ipAddressDao.listByAssociatedVpc(vpc.getId(), true);
|
||||
if (CollectionUtils.isEmpty(ips)) {
|
||||
String err = String.format("Cannot find a source NAT IP for the VPC %s", vpc.getName());
|
||||
s_logger.error(err);
|
||||
logger.error(err);
|
||||
throw new CloudRuntimeException(err);
|
||||
}
|
||||
ips = ips.stream().filter(x -> !x.getAddress().addr().equals(nic.getIPv4Address())).collect(Collectors.toList());
|
||||
|
|
@ -135,11 +136,11 @@ public class NsxPublicNetworkGuru extends PublicNetworkGuru {
|
|||
boolean sourceNatEnabled = !NetworkOffering.NsxMode.ROUTED.name().equals(vpcVO.getNsxMode()) &&
|
||||
vpcOfferingServiceMapDao.areServicesSupportedByVpcOffering(vpc.getVpcOfferingId(), services);
|
||||
|
||||
s_logger.info(String.format("Creating Tier 1 Gateway for VPC %s", vpc.getName()));
|
||||
logger.info(String.format("Creating Tier 1 Gateway for VPC %s", vpc.getName()));
|
||||
boolean result = nsxService.createVpcNetwork(dataCenterId, accountId, domainId, resourceId, vpc.getName(), sourceNatEnabled);
|
||||
if (!result) {
|
||||
String msg = String.format("Error creating Tier 1 Gateway for VPC %s", vpc.getName());
|
||||
s_logger.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
|
||||
|
|
@ -153,13 +154,13 @@ public class NsxPublicNetworkGuru extends PublicNetworkGuru {
|
|||
|
||||
String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(domainId, accountId, dataCenterId, resourceId, isForVpc);
|
||||
String translatedIp = ipAddress.getAddress().addr();
|
||||
s_logger.debug(String.format("Creating NSX Nat Rule for Tier1 GW %s for translated IP %s", tier1GatewayName, translatedIp));
|
||||
logger.debug(String.format("Creating NSX Nat Rule for Tier1 GW %s for translated IP %s", tier1GatewayName, translatedIp));
|
||||
String natRuleId = NsxControllerUtils.getNsxNatRuleId(domainId, accountId, dataCenterId, resourceId, isForVpc);
|
||||
CreateOrUpdateNsxTier1NatRuleCommand cmd = NsxHelper.createOrUpdateNsxNatRuleCommand(domainId, accountId, dataCenterId, tier1GatewayName, "SNAT", translatedIp, natRuleId);
|
||||
NsxAnswer nsxAnswer = nsxControllerUtils.sendNsxCommand(cmd, dataCenterId);
|
||||
if (!nsxAnswer.getResult()) {
|
||||
String msg = String.format("Could not create NSX Nat Rule on Tier1 Gateway %s for IP %s", tier1GatewayName, translatedIp);
|
||||
s_logger.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ import org.apache.cloudstack.agent.api.DeleteNsxTier1GatewayCommand;
|
|||
import org.apache.cloudstack.resource.NsxNetworkRule;
|
||||
import org.apache.cloudstack.utils.NsxControllerUtils;
|
||||
import org.apache.cloudstack.utils.NsxHelper;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
|
@ -54,7 +55,7 @@ public class NsxServiceImpl implements NsxService {
|
|||
@Inject
|
||||
NetworkDao networkDao;
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(NsxServiceImpl.class);
|
||||
protected Logger logger = LogManager.getLogger(getClass());
|
||||
|
||||
public boolean createVpcNetwork(Long zoneId, long accountId, long domainId, Long vpcId, String vpcName, boolean sourceNatEnabled) {
|
||||
CreateNsxTier1GatewayCommand createNsxTier1GatewayCommand =
|
||||
|
|
@ -73,13 +74,13 @@ public class NsxServiceImpl implements NsxService {
|
|||
long zoneId = vpc.getZoneId();
|
||||
long vpcId = vpc.getId();
|
||||
|
||||
LOGGER.debug(String.format("Updating the source NAT IP for NSX VPC %s to IP: %s", vpc.getName(), address.getAddress().addr()));
|
||||
logger.debug(String.format("Updating the source NAT IP for NSX VPC %s to IP: %s", vpc.getName(), address.getAddress().addr()));
|
||||
String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(domainId, accountId, zoneId, vpcId, true);
|
||||
String sourceNatRuleId = NsxControllerUtils.getNsxNatRuleId(domainId, accountId, zoneId, vpcId, true);
|
||||
CreateOrUpdateNsxTier1NatRuleCommand cmd = NsxHelper.createOrUpdateNsxNatRuleCommand(domainId, accountId, zoneId, tier1GatewayName, "SNAT", address.getAddress().addr(), sourceNatRuleId);
|
||||
NsxAnswer answer = nsxControllerUtils.sendNsxCommand(cmd, zoneId);
|
||||
if (!answer.getResult()) {
|
||||
LOGGER.error(String.format("Could not update the source NAT IP address for VPC %s: %s", vpc.getName(), answer.getDetails()));
|
||||
logger.error(String.format("Could not update the source NAT IP address for VPC %s: %s", vpc.getName(), answer.getDetails()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -110,7 +111,7 @@ public class NsxServiceImpl implements NsxService {
|
|||
NsxAnswer result = nsxControllerUtils.sendNsxCommand(deleteNsxSegmentCommand, network.getDataCenterId());
|
||||
if (!result.getResult()) {
|
||||
String msg = String.format("Could not remove the NSX segment for network %s: %s", network.getName(), result.getDetails());
|
||||
LOGGER.error(msg);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ import com.cloud.network.element.NsxProviderVO;
|
|||
import org.apache.cloudstack.NsxAnswer;
|
||||
import org.apache.cloudstack.agent.api.NsxCommand;
|
||||
import org.apache.cloudstack.service.NsxApiClient;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -33,7 +34,7 @@ import static java.util.Objects.isNull;
|
|||
|
||||
@Component
|
||||
public class NsxControllerUtils {
|
||||
private static final Logger s_logger = Logger.getLogger(NsxControllerUtils.class);
|
||||
protected Logger logger = LogManager.getLogger(getClass());
|
||||
|
||||
@Inject
|
||||
private AgentManager agentMgr;
|
||||
|
|
@ -52,13 +53,13 @@ public class NsxControllerUtils {
|
|||
public NsxAnswer sendNsxCommand(NsxCommand cmd, long zoneId) throws IllegalArgumentException {
|
||||
NsxProviderVO nsxProviderVO = nsxProviderDao.findByZoneId(zoneId);
|
||||
if (nsxProviderVO == null) {
|
||||
s_logger.error("No NSX controller was found!");
|
||||
logger.error("No NSX controller was found!");
|
||||
throw new InvalidParameterValueException("Failed to find an NSX controller");
|
||||
}
|
||||
Answer answer = agentMgr.easySend(nsxProviderVO.getHostId(), cmd);
|
||||
|
||||
if (answer == null || !answer.getResult()) {
|
||||
s_logger.error("NSX API Command failed");
|
||||
logger.error("NSX API Command failed");
|
||||
throw new InvalidParameterValueException("Failed API call to NSX controller");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue