Search in sources :

Example 11 with CommandRetryUtility

use of com.cloud.network.utils.CommandRetryUtility in project cloudstack by apache.

the class NiciraNvpFindLogicalRouterPortCommandWrapper method execute.

@Override
public Answer execute(FindLogicalRouterPortCommand command, NiciraNvpResource niciraNvpResource) {
    final String logicalRouterUuid = command.getLogicalRouterUuid();
    final String attachmentLswitchUuid = command.getAttachmentLswitchUuid();
    final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
    s_logger.debug("Finding Logical Router Port in Logical Router " + logicalRouterUuid + " and attachmentLSwitchUuid " + attachmentLswitchUuid);
    try {
        List<LogicalRouterPort> lRouterPorts = niciraNvpApi.findLogicalRouterPortByAttachmentLSwitchUuid(logicalRouterUuid, attachmentLswitchUuid);
        if (lRouterPorts.size() == 0) {
            return new FindLogicalRouterPortAnswer(command, false, "Logical Router Port not found", null);
        } else {
            return new FindLogicalRouterPortAnswer(command, true, "Logical Router Port found", lRouterPorts.get(0).getUuid());
        }
    } catch (NiciraNvpApiException e) {
        s_logger.error("Error finding Logical Router Port due to: " + e.getMessage());
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, FindLogicalRouterPortAnswer.class, e);
    }
}
Also used : LogicalRouterPort(com.cloud.network.nicira.LogicalRouterPort) FindLogicalRouterPortAnswer(com.cloud.agent.api.FindLogicalRouterPortAnswer) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException)

Example 12 with CommandRetryUtility

use of com.cloud.network.utils.CommandRetryUtility in project cloudstack by apache.

the class NiciraNvpFindLogicalSwitchPortCommandWrapper method execute.

@Override
public Answer execute(final FindLogicalSwitchPortCommand command, final NiciraNvpResource niciraNvpResource) {
    final String logicalSwitchUuid = command.getLogicalSwitchUuid();
    final String logicalSwitchPortUuid = command.getLogicalSwitchPortUuid();
    final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
    try {
        final List<LogicalSwitchPort> ports = niciraNvpApi.findLogicalSwitchPortsByUuid(logicalSwitchUuid, logicalSwitchPortUuid);
        if (ports.size() == 0) {
            return new FindLogicalSwitchPortAnswer(command, false, "Logical switchport " + logicalSwitchPortUuid + " not found", null);
        } else {
            return new FindLogicalSwitchPortAnswer(command, true, "Logical switchport " + logicalSwitchPortUuid + " found", logicalSwitchPortUuid);
        }
    } catch (final NiciraNvpApiException e) {
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, FindLogicalSwitchPortAnswer.class, e);
    }
}
Also used : FindLogicalSwitchPortAnswer(com.cloud.agent.api.FindLogicalSwitchPortAnswer) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort)

Example 13 with CommandRetryUtility

use of com.cloud.network.utils.CommandRetryUtility in project cloudstack by apache.

the class NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper method handleException.

private Answer handleException(NiciraNvpApiException e, ConfigureSharedNetworkVlanIdCommand command, NiciraNvpResource niciraNvpResource) {
    if (HttpStatusCodeHelper.isConflict(e.getErrorCode())) {
        s_logger.warn("There's been a conflict in NSX side, aborting implementation");
        return new ConfigureSharedNetworkVlanIdAnswer(command, false, "FAILED: There's been a conflict in NSX side");
    } else {
        s_logger.warn("Error code: " + e.getErrorCode() + ", retrying");
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, ConfigureSharedNetworkVlanIdAnswer.class, e);
    }
}
Also used : CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) ConfigureSharedNetworkVlanIdAnswer(com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer)

Example 14 with CommandRetryUtility

use of com.cloud.network.utils.CommandRetryUtility in project cloudstack by apache.

the class NiciraNvpConfigureStaticNatRulesCommandWrapper method execute.

@Override
public Answer execute(final ConfigureStaticNatRulesOnLogicalRouterCommand command, final NiciraNvpResource niciraNvpResource) {
    final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
    try {
        final List<NatRule> existingRules = niciraNvpApi.findNatRulesByLogicalRouterUuid(command.getLogicalRouterUuid());
        for (final StaticNatRuleTO rule : command.getRules()) {
            final NatRule[] rulepair = niciraNvpResource.generateStaticNatRulePair(rule.getDstIp(), rule.getSrcIp());
            NatRule incoming = null;
            NatRule outgoing = null;
            for (final NatRule storedRule : existingRules) {
                if (storedRule.equalsIgnoreUuid(rulepair[1])) {
                    // The outgoing rule exists
                    outgoing = storedRule;
                    s_logger.debug("Found matching outgoing rule " + outgoing.getUuid());
                    if (incoming != null) {
                        break;
                    }
                } else if (storedRule.equalsIgnoreUuid(rulepair[0])) {
                    // The incoming rule exists
                    incoming = storedRule;
                    s_logger.debug("Found matching incoming rule " + incoming.getUuid());
                    if (outgoing != null) {
                        break;
                    }
                }
            }
            if (incoming != null && outgoing != null) {
                if (rule.revoked()) {
                    s_logger.debug("Deleting incoming rule " + incoming.getUuid());
                    niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), incoming.getUuid());
                    s_logger.debug("Deleting outgoing rule " + outgoing.getUuid());
                    niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), outgoing.getUuid());
                }
            } else {
                if (rule.revoked()) {
                    s_logger.warn("Tried deleting a rule that does not exist, " + rule.getSrcIp() + " -> " + rule.getDstIp());
                    break;
                }
                rulepair[0] = niciraNvpApi.createLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[0]);
                s_logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[0]));
                try {
                    rulepair[1] = niciraNvpApi.createLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[1]);
                    s_logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[1]));
                } catch (final NiciraNvpApiException ex) {
                    s_logger.debug("Failed to create SourceNatRule, rolling back DestinationNatRule");
                    niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[0].getUuid());
                    // Rethrow original exception
                    throw ex;
                }
            }
        }
        return new ConfigureStaticNatRulesOnLogicalRouterAnswer(command, true, command.getRules().size() + " StaticNat rules applied");
    } catch (final NiciraNvpApiException e) {
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, ConfigureStaticNatRulesOnLogicalRouterAnswer.class, e);
    }
}
Also used : StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) NatRule(com.cloud.network.nicira.NatRule) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) ConfigureStaticNatRulesOnLogicalRouterAnswer(com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterAnswer)

Example 15 with CommandRetryUtility

use of com.cloud.network.utils.CommandRetryUtility in project cloudstack by apache.

the class NiciraNvpCreateLogicalSwitchPortCommandWrapper method execute.

@Override
public Answer execute(final CreateLogicalSwitchPortCommand command, final NiciraNvpResource niciraNvpResource) {
    final NiciraNvpUtilities niciraNvpUtilities = niciraNvpResource.getNiciraNvpUtilities();
    final String logicalSwitchUuid = command.getLogicalSwitchUuid();
    final String attachmentUuid = command.getAttachmentUuid();
    try {
        final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
        final LogicalSwitchPort logicalSwitchPort = niciraNvpUtilities.createLogicalSwitchPort(command);
        final LogicalSwitchPort newPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, logicalSwitchPort);
        try {
            niciraNvpApi.updateLogicalSwitchPortAttachment(command.getLogicalSwitchUuid(), newPort.getUuid(), new VifAttachment(attachmentUuid));
        } catch (final NiciraNvpApiException ex) {
            s_logger.warn("modifyLogicalSwitchPort failed after switchport was created, removing switchport");
            niciraNvpApi.deleteLogicalSwitchPort(command.getLogicalSwitchUuid(), newPort.getUuid());
            // Rethrow the original exception
            throw ex;
        }
        return new CreateLogicalSwitchPortAnswer(command, true, "Logical switch port " + newPort.getUuid() + " created", newPort.getUuid());
    } catch (final NiciraNvpApiException e) {
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, CreateLogicalSwitchPortAnswer.class, e);
    }
}
Also used : NiciraNvpUtilities(com.cloud.network.resource.NiciraNvpUtilities) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) CreateLogicalSwitchPortAnswer(com.cloud.agent.api.CreateLogicalSwitchPortAnswer) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort) VifAttachment(com.cloud.network.nicira.VifAttachment)

Aggregations

CommandRetryUtility (com.cloud.network.utils.CommandRetryUtility)15 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)13 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)13 LogicalRouterPort (com.cloud.network.nicira.LogicalRouterPort)4 LogicalSwitchPort (com.cloud.network.nicira.LogicalSwitchPort)4 NiciraNvpTag (com.cloud.network.nicira.NiciraNvpTag)4 ArrayList (java.util.ArrayList)4 NiciraNvpUtilities (com.cloud.network.resource.NiciraNvpUtilities)3 ConfigureSharedNetworkUuidAnswer (com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer)2 LogicalSwitch (com.cloud.network.nicira.LogicalSwitch)2 NatRule (com.cloud.network.nicira.NatRule)2 PatchAttachment (com.cloud.network.nicira.PatchAttachment)2 VifAttachment (com.cloud.network.nicira.VifAttachment)2 ConfigurePortForwardingRulesOnLogicalRouterAnswer (com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer)1 ConfigurePublicIpsOnLogicalRouterAnswer (com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer)1 ConfigureSharedNetworkVlanIdAnswer (com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer)1 ConfigureStaticNatRulesOnLogicalRouterAnswer (com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterAnswer)1 CreateLogicalRouterAnswer (com.cloud.agent.api.CreateLogicalRouterAnswer)1 CreateLogicalSwitchAnswer (com.cloud.agent.api.CreateLogicalSwitchAnswer)1 CreateLogicalSwitchPortAnswer (com.cloud.agent.api.CreateLogicalSwitchPortAnswer)1