use of com.cloud.utils.rest.CosmicRESTException in project cosmic by MissionCriticalCloud.
the class NiciraNvpApi method findLogicalSwitchPortUuidByVifAttachmentUuid.
public String findLogicalSwitchPortUuidByVifAttachmentUuid(final String logicalSwitchUuid, final String vifAttachmentUuid) throws NiciraNvpApiException {
final String uri = buildLogicalSwitchElementUri(logicalSwitchUuid, LPORT_PATH_SEGMENT);
final Map<String, String> params = buildBasicParametersMap(UUID_QUERY_PARAMETER);
params.put(NiciraConstants.ATTACHMENT_VIF_UUID_QUERY_PARAMETER_NAME, vifAttachmentUuid);
final NiciraNvpList<LogicalSwitchPort> niciraList;
try {
final Type niciraListType = new TypeToken<NiciraNvpList<LogicalSwitchPort>>() {
}.getType();
niciraList = restConnector.executeRetrieveObject(niciraListType, uri, params);
} catch (final CosmicRESTException e) {
throw new NiciraNvpApiException(e);
}
final List<LogicalSwitchPort> lspl = niciraList.getResults();
final int listSize = lspl.size();
if (listSize != 1) {
return null;
}
final LogicalSwitchPort lsp = lspl.get(0);
return lsp.getUuid();
}
use of com.cloud.utils.rest.CosmicRESTException in project cosmic by MissionCriticalCloud.
the class NiciraNvpApi method findLogicalSwitchPortsByUuid.
public List<LogicalSwitchPort> findLogicalSwitchPortsByUuid(final String logicalSwitchUuid, final String logicalSwitchPortUuid) throws NiciraNvpApiException {
final String uri = buildLogicalSwitchElementUri(logicalSwitchUuid, LPORT_PATH_SEGMENT);
final Map<String, String> params = buildBasicParametersMap(UUID_QUERY_PARAMETER);
params.put(UUID_QUERY_PARAMETER, logicalSwitchPortUuid);
try {
final Type niciraListType = new TypeToken<NiciraNvpList<LogicalSwitchPort>>() {
}.getType();
return restConnector.<NiciraNvpList<LogicalSwitchPort>>executeRetrieveObject(niciraListType, uri, params).getResults();
} catch (final CosmicRESTException e) {
throw new NiciraNvpApiException(e);
}
}
use of com.cloud.utils.rest.CosmicRESTException in project cosmic by MissionCriticalCloud.
the class NiciraNvpApi method findLogicalRouterPortByGatewayServiceAndVlanId.
public List<LogicalRouterPort> findLogicalRouterPortByGatewayServiceAndVlanId(final String logicalRouterUuid, final String gatewayServiceUuid, final long vlanId) throws NiciraNvpApiException {
final String uri = buildLogicalRouterElementUri(logicalRouterUuid, LPORT_PATH_SEGMENT);
final Map<String, String> params = buildBasicParametersMap(WILDCARD_QUERY_PARAMETER);
params.put(ATTACHMENT_GWSVC_UUID_QUERY_PARAMETER, gatewayServiceUuid);
params.put(NiciraConstants.ATTACHMENT_VLAN_PARAMETER, Long.toString(vlanId));
try {
final Type niciraListType = new TypeToken<NiciraNvpList<LogicalRouterPort>>() {
}.getType();
return restConnector.<NiciraNvpList<LogicalRouterPort>>executeRetrieveObject(niciraListType, uri, params).getResults();
} catch (final CosmicRESTException e) {
throw new NiciraNvpApiException(e);
}
}
use of com.cloud.utils.rest.CosmicRESTException in project cosmic by MissionCriticalCloud.
the class NiciraRestClient method execute.
private CloseableHttpResponse execute(final HttpUriRequest request, final int previousStatusCode) throws CosmicRESTException {
if (counter.hasReachedExecutionLimit()) {
throw new CosmicRESTException("Reached max executions limit of " + executionLimit);
}
counter.incrementExecutionCounter();
s_logger.debug("Executing " + request.getMethod() + " request [execution count = " + counter.getValue() + "]");
final CloseableHttpResponse response = super.execute(request);
final StatusLine statusLine = response.getStatusLine();
final int statusCode = statusLine.getStatusCode();
s_logger.debug("Status of last request: " + statusLine.toString());
if (HttpStatusCodeHelper.isUnauthorized(statusCode)) {
return handleUnauthorizedResponse(request, previousStatusCode, response, statusCode);
} else if (HttpStatusCodeHelper.isSuccess(statusCode)) {
return handleSuccessResponse(request, response);
} else {
throw new CosmicRESTException("Unexpected status code: " + statusCode);
}
}
Aggregations