Search in sources :

Example 6 with CosmicRESTException

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();
}
Also used : Type(java.lang.reflect.Type) CosmicRESTException(com.cloud.utils.rest.CosmicRESTException)

Example 7 with CosmicRESTException

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);
    }
}
Also used : Type(java.lang.reflect.Type) CosmicRESTException(com.cloud.utils.rest.CosmicRESTException)

Example 8 with CosmicRESTException

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);
    }
}
Also used : Type(java.lang.reflect.Type) CosmicRESTException(com.cloud.utils.rest.CosmicRESTException)

Example 9 with CosmicRESTException

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);
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) CosmicRESTException(com.cloud.utils.rest.CosmicRESTException)

Aggregations

CosmicRESTException (com.cloud.utils.rest.CosmicRESTException)9 Type (java.lang.reflect.Type)6 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 ConfigurationException (javax.naming.ConfigurationException)1 StatusLine (org.apache.http.StatusLine)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1