Search in sources :

Example 1 with CosmicRESTException

use of com.cloud.utils.rest.CosmicRESTException in project cosmic by MissionCriticalCloud.

the class NiciraNvpResource method configure.

@Override
public boolean configure(final String ignoredName, final Map<String, Object> params) throws ConfigurationException {
    this.name = (String) params.get("name");
    if (this.name == null) {
        throw new ConfigurationException("Unable to find name");
    }
    this.guid = (String) params.get("guid");
    if (this.guid == null) {
        throw new ConfigurationException("Unable to find the guid");
    }
    this.zoneId = (String) params.get("zoneId");
    if (this.zoneId == null) {
        throw new ConfigurationException("Unable to find zone");
    }
    final String ips = (String) params.get("ip");
    if (ips == null) {
        throw new ConfigurationException("Unable to find IPs");
    }
    final String adminuser = (String) params.get("adminuser");
    if (adminuser == null) {
        throw new ConfigurationException("Unable to find admin username");
    }
    final String adminpass = (String) params.get("adminpass");
    if (adminpass == null) {
        throw new ConfigurationException("Unable to find admin password");
    }
    this.niciraNvpUtilities = NiciraNvpUtilities.getInstance();
    this.retryUtility = CommandRetryUtility.getInstance();
    this.retryUtility.setServerResource(this);
    try {
        for (final String ip : ips.split(",")) {
            this.niciraNvpApis.add(createNiciraNvpApi(ip, adminuser, adminpass));
        }
    } catch (final CosmicRESTException e) {
        throw new ConfigurationException("Could not create a Nicira Nvp API client: " + e.getMessage());
    }
    return true;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) CosmicRESTException(com.cloud.utils.rest.CosmicRESTException)

Example 2 with CosmicRESTException

use of com.cloud.utils.rest.CosmicRESTException in project cosmic by MissionCriticalCloud.

the class NiciraNvpApi method findNatRulesByLogicalRouterUuid.

public List<NatRule> findNatRulesByLogicalRouterUuid(final String logicalRouterUuid) throws NiciraNvpApiException {
    final String uri = buildLogicalRouterElementUri(logicalRouterUuid, NAT_PATH_SEGMENT);
    final Map<String, String> params = buildBasicParametersMap(WILDCARD_QUERY_PARAMETER);
    try {
        final Type niciraListType = new TypeToken<NiciraNvpList<NatRule>>() {
        }.getType();
        return restConnector.<NiciraNvpList<NatRule>>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 3 with CosmicRESTException

use of com.cloud.utils.rest.CosmicRESTException in project cosmic by MissionCriticalCloud.

the class NiciraNvpApi method findLogicalRouterPortsByUuid.

public List<LogicalRouterPort> findLogicalRouterPortsByUuid(final String logicalRouterUuid, final String logicalRouterPortUuid) throws NiciraNvpApiException {
    final String uri = buildLogicalRouterElementUri(logicalRouterUuid, LPORT_PATH_SEGMENT);
    final Map<String, String> params = buildBasicParametersMap(UUID_QUERY_PARAMETER);
    params.put(UUID_QUERY_PARAMETER, logicalRouterPortUuid);
    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 4 with CosmicRESTException

use of com.cloud.utils.rest.CosmicRESTException in project cosmic by MissionCriticalCloud.

the class NiciraNvpApi method findLogicalRouterPortByGatewayServiceUuid.

public List<LogicalRouterPort> findLogicalRouterPortByGatewayServiceUuid(final String logicalRouterUuid, final String l3GatewayServiceUuid) 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, l3GatewayServiceUuid);
    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 5 with CosmicRESTException

use of com.cloud.utils.rest.CosmicRESTException in project cosmic by MissionCriticalCloud.

the class NiciraRestClient method handleUnauthorizedResponse.

private CloseableHttpResponse handleUnauthorizedResponse(final HttpUriRequest request, final int previousStatusCode, final CloseableHttpResponse response, final int statusCode) throws CosmicRESTException {
    super.closeResponse(response);
    if (HttpStatusCodeHelper.isUnauthorized(previousStatusCode)) {
        s_logger.error(responseToErrorMessage(response));
        throw new CosmicRESTException("Two consecutive failed attempts to authenticate against REST server");
    }
    final HttpUriRequest authenticateRequest = createAuthenticationRequest();
    final CloseableHttpResponse loginResponse = execute(authenticateRequest, statusCode);
    final int loginStatusCode = loginResponse.getStatusLine().getStatusCode();
    super.closeResponse(loginResponse);
    return execute(request, loginStatusCode);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) 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