Search in sources :

Example 1 with OpenStackResponseException

use of com.woorea.openstack.base.client.OpenStackResponseException in project AJSC by att.

the class OpenStackComputeService method getExtensions.

/**
 * Returns the set of extensions loaded, if any
 *
 * @return The list of extensions installed, if any
 * @throws ZoneException
 *             If anything fails
 */
public List<String> getExtensions() throws ZoneException {
    connect();
    Context context = getContext();
    ArrayList<String> extensions = new ArrayList<>();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        for (Extension extension : nova.getClient().extensions().list(true).execute()) {
            extensions.add(extension.getName());
        }
    } catch (OpenStackBaseException e) {
        if (e instanceof OpenStackResponseException) {
            OpenStackResponseException osre = (OpenStackResponseException) e;
            if (osre.getStatus() != 404) {
                ExceptionMapper.mapException(e);
            }
        } else {
            ExceptionMapper.mapException(e);
        }
    }
    return extensions;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) Extension(com.woorea.openstack.nova.model.Extension) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList)

Example 2 with OpenStackResponseException

use of com.woorea.openstack.base.client.OpenStackResponseException in project AJSC by att.

the class OpenStackComputeService method getPorts.

/**
 * Gets the ports connected to a specific server
 *
 * @throws ZoneException
 *             If the server is null or invalid, if the context is closed,
 *             or if the context has not been authenticated, or if the
 *             authentication has expired
 * @see com.att.cdp.zones.ComputeService#getPorts(com.att.cdp.zones.model.Server)
 */
@SuppressWarnings("nls")
@Override
public List<Port> getPorts(Server server) throws ZoneException {
    checkArg(server, "server");
    connect();
    trackRequest();
    RequestState.put(RequestState.SERVER, server.getId());
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    List<Port> list = new ArrayList<>();
    try {
        InterfaceAttachments attachments = nova.getClient().servers().listInterfaceAttachments(server.getId()).execute();
        for (InterfaceAttachment attachment : attachments.getList()) {
            OpenStackPort port = new OpenStackPort(getContext(), attachment);
            list.add(port);
        }
    } catch (OpenStackConnectException | OpenStackResponseException e) {
        ExceptionMapper.mapException(e);
    }
    return list;
}
Also used : OpenStackPort(com.att.cdp.openstack.model.OpenStackPort) InterfaceAttachments(com.woorea.openstack.nova.model.InterfaceAttachments) InterfaceAttachment(com.woorea.openstack.nova.model.InterfaceAttachment) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) Port(com.att.cdp.zones.model.Port) OpenStackPort(com.att.cdp.openstack.model.OpenStackPort) ArrayList(java.util.ArrayList) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 3 with OpenStackResponseException

use of com.woorea.openstack.base.client.OpenStackResponseException in project AJSC by att.

the class AbstractOpenStackIdentityService method getKeyPair.

/**
 * @see com.att.cdp.zones.IdentityService#getKeyPair(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public KeyPair getKeyPair(String name) throws ZoneException {
    trackRequest();
    RequestState.put(RequestState.KEYPAIR, name);
    Context context = getContext();
    if (context.isLoggedIn()) {
        NovaConnector connector = ((OpenStackContext) context).getNovaConnector();
        KeyPairs pairs;
        try {
            pairs = connector.getClient().keyPairs().list().execute();
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Compute", connector.getEndpoint()), e);
        } catch (OpenStackResponseException e) {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "get key-pair " + name), e);
        }
        if (pairs == null || pairs.getList() == null) {
            return null;
        }
        for (com.woorea.openstack.nova.model.KeyPair pair : pairs.getList()) {
            if (pair.getName().equals(name)) {
                return new OpenStackKeyPair(context, pair);
            }
        }
        return null;
    }
    throw new ZoneException("Unable to retrieve key-pairs when the context has not been logged in and authenticated");
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) KeyPairs(com.woorea.openstack.nova.model.KeyPairs) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackKeyPair(com.att.cdp.openstack.model.OpenStackKeyPair) NovaConnector(com.att.cdp.openstack.connectors.NovaConnector) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 4 with OpenStackResponseException

use of com.woorea.openstack.base.client.OpenStackResponseException in project AJSC by att.

the class AbstractOpenStackIdentityService method getTenants.

public Set<Tenant> getTenants() throws ZoneException {
    checkLoggedIn();
    Context context = getContext();
    trackRequest();
    Set<Tenant> tenants = new HashSet<Tenant>();
    Keystone keystone = getKeystone();
    keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
    try {
        Tenants tenantList = keystone.tenants().list().execute();
        for (com.woorea.openstack.keystone.model.Tenant t : tenantList.getList()) {
            tenants.add(new OpenStackTenant((OpenStackContext) context, t));
        }
    } catch (OpenStackConnectException e) {
        throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Identity", keystoneUrl), e);
    } catch (OpenStackResponseException e) {
        throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "get tenant " + tenantName), e);
    }
    return tenants;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackTenant(com.att.cdp.openstack.model.OpenStackTenant) Tenants(com.woorea.openstack.keystone.model.Tenants) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) Tenant(com.att.cdp.zones.model.Tenant) OpenStackTenant(com.att.cdp.openstack.model.OpenStackTenant) Keystone(com.woorea.openstack.keystone.Keystone) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) HashSet(java.util.HashSet)

Example 5 with OpenStackResponseException

use of com.woorea.openstack.base.client.OpenStackResponseException in project AJSC by att.

the class AbstractOpenStackIdentityService method authenticate.

/**
 * @see com.att.cdp.zones.IdentityService#authenticate(java.lang.String, java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public void authenticate(String principal, String credential) throws IllegalArgumentException, ZoneException {
    OpenStackContext context = (OpenStackContext) getContext();
    checkPrincipal(principal);
    checkCredential(credential);
    if (!context.isLoggedIn()) {
        try {
            keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
            tenantName = context.getProperties().getProperty(ContextFactory.PROPERTY_TENANT);
            /*
                 * DH868g: Allow the specification of a client connector to override the default mechanism of the
                 * service loader. This is needed to support use within an OSGi container.
                 */
            keystone = new Keystone(keystoneUrl, context.getClientConnector());
            /*
                 * dh868g: configure the client object to set any defined proxy and trusted host list
                 */
            String proxyHost = context.getProperties().getProperty(ContextFactory.PROPERTY_PROXY_HOST);
            String proxyPort = context.getProperties().getProperty(ContextFactory.PROPERTY_PROXY_PORT);
            String trustedHosts = context.getProperties().getProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "");
            if (proxyHost != null && proxyHost.length() > 0) {
                getKeystone().getProperties().setProperty(com.woorea.openstack.common.client.Constants.PROXY_HOST, proxyHost);
                getKeystone().getProperties().setProperty(com.woorea.openstack.common.client.Constants.PROXY_PORT, proxyPort);
            }
            if (trustedHosts != null) {
                getKeystone().getProperties().setProperty(com.woorea.openstack.common.client.Constants.TRUST_HOST_LIST, trustedHosts);
            }
            // access with unscoped token
            Authentication authentication = new UsernamePassword(principal, credential);
            TokensResource tokens = getKeystone().tokens();
            TokensResource.Authenticate authenticate = tokens.authenticate(authentication);
            authenticate = authenticate.withTenantName(tenantName);
            access = authenticate.execute();
            expiresLocal = getLocalExpiration(access);
            tenant = new OpenStackTenant(context, access.getToken().getTenant());
            context.setTenant(tenant);
            tokenProvider = new OpenStackSimpleTokenProvider(access.getToken().getId());
            getKeystone().setTokenProvider(tokenProvider);
            List<Access.Service> services = access.getServiceCatalog();
            OpenStackContext osContext = context;
            osContext.registerServices(services);
            // Testing that we can access tenants already
            Tenants tenantList = getKeystone().tenants().list().execute();
            for (com.woorea.openstack.keystone.model.Tenant t : tenantList.getList()) {
                System.out.println(t);
            }
        } catch (OpenStackResponseException e) {
            throw new AuthenticationException(EELFResourceManager.format(OSMsg.PAL_OS_FAILED_PROVIDER_AUTHENTICATION, e, principal, tenantName));
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Identity", keystoneUrl), e);
        }
    }
}
Also used : OpenStackTenant(com.att.cdp.openstack.model.OpenStackTenant) AuthenticationException(com.att.cdp.exceptions.AuthenticationException) CommonIdentityService(com.att.cdp.openstack.CommonIdentityService) Tenants(com.woorea.openstack.keystone.model.Tenants) TokensResource(com.woorea.openstack.keystone.api.TokensResource) UsernamePassword(com.woorea.openstack.keystone.model.authentication.UsernamePassword) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) Keystone(com.woorea.openstack.keystone.Keystone) OpenStackSimpleTokenProvider(com.woorea.openstack.base.client.OpenStackSimpleTokenProvider) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) Authentication(com.woorea.openstack.keystone.model.Authentication) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Aggregations

OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)15 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)12 OpenStackContext (com.att.cdp.openstack.OpenStackContext)9 ContextConnectionException (com.att.cdp.exceptions.ContextConnectionException)8 Context (com.att.cdp.zones.Context)8 ZoneException (com.att.cdp.exceptions.ZoneException)7 ArrayList (java.util.ArrayList)6 NovaConnector (com.att.cdp.openstack.connectors.NovaConnector)4 Keystone (com.woorea.openstack.keystone.Keystone)4 OpenStackKeyPair (com.att.cdp.openstack.model.OpenStackKeyPair)3 OpenStackTenant (com.att.cdp.openstack.model.OpenStackTenant)3 Tenants (com.woorea.openstack.keystone.model.Tenants)3 OpenStackPort (com.att.cdp.openstack.model.OpenStackPort)2 Port (com.att.cdp.zones.model.Port)2 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)2 Extension (com.woorea.openstack.nova.model.Extension)2 InterfaceAttachment (com.woorea.openstack.nova.model.InterfaceAttachment)2 InterfaceAttachmentForCreate (com.woorea.openstack.nova.model.InterfaceAttachmentForCreate)2 InterfaceAttachments (com.woorea.openstack.nova.model.InterfaceAttachments)2 KeyPairs (com.woorea.openstack.nova.model.KeyPairs)2