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);
}
}
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);
}
}
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);
}
}
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);
}
}
use of com.cloud.network.utils.CommandRetryUtility in project cloudstack by apache.
the class NiciraNvpUpdateLogicalSwitchPortCommandWrapper method execute.
@Override
public Answer execute(final UpdateLogicalSwitchPortCommand command, final NiciraNvpResource niciraNvpResource) {
final NiciraNvpUtilities niciraNvpUtilities = niciraNvpResource.getNiciraNvpUtilities();
final String logicalSwitchUuid = command.getLogicalSwitchUuid();
final String logicalSwitchPortUuid = command.getLogicalSwitchPortUuid();
final String attachmentUuid = command.getAttachmentUuid();
final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
try {
// Tags set to scope cs_account and account name
final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
final VifAttachment vifAttachment = niciraNvpUtilities.createVifAttachment(attachmentUuid);
niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, logicalSwitchPortUuid, vifAttachment);
return new UpdateLogicalSwitchPortAnswer(command, true, "Attachment for " + logicalSwitchPortUuid + " updated", logicalSwitchPortUuid);
} catch (final NiciraNvpApiException e) {
final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
retryUtility.addRetry(command, NUM_RETRIES);
return retryUtility.retry(command, UpdateLogicalSwitchPortAnswer.class, e);
}
}
Aggregations