Search in sources :

Example 16 with OpenStackResourceException

use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException in project cloudbreak by hortonworks.

the class OpenStackNetworkResourceBuilder method delete.

@Override
public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource, Network network) {
    try {
        OSClient<?> osClient = createOSClient(auth);
        deAllocateFloatingIps(context, osClient);
        NeutronNetworkView neutronView = new NeutronNetworkView(network);
        if (!neutronView.isExistingNetwork()) {
            ActionResponse response = osClient.networking().network().delete(resource.getReference());
            return checkDeleteResponse(response, resourceType(), auth, resource, "Network deletion failed");
        }
        return null;
    } catch (OS4JException ex) {
        throw new OpenStackResourceException("Network deletion failed", resourceType(), resource.getName(), ex);
    }
}
Also used : OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView) OS4JException(org.openstack4j.api.exceptions.OS4JException) ActionResponse(org.openstack4j.model.common.ActionResponse)

Example 17 with OpenStackResourceException

use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException in project cloudbreak by hortonworks.

the class OpenStackRouterResourceBuilder method checkStatus.

@Override
protected boolean checkStatus(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) {
    CloudContext cloudContext = auth.getCloudContext();
    OSClient<?> osClient = createOSClient(auth);
    Router osRouter = osClient.networking().router().get(resource.getReference());
    if (osRouter != null && context.isBuild()) {
        State routerStatus = osRouter.getStatus();
        if (State.ERROR == routerStatus) {
            throw new OpenStackResourceException("Router in failed state", resource.getType(), utils.getStackName(auth), cloudContext.getId(), resource.getName());
        }
        return routerStatus == State.ACTIVE;
    } else {
        return osRouter == null && !context.isBuild();
    }
}
Also used : State(org.openstack4j.model.network.State) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException) Router(org.openstack4j.model.network.Router)

Example 18 with OpenStackResourceException

use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException in project cloudbreak by hortonworks.

the class OpenStackAttachedDiskResourceBuilder method checkStatus.

@Override
protected boolean checkStatus(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) {
    CloudContext cloudContext = auth.getCloudContext();
    OSClient<?> osClient = createOSClient(auth);
    Volume osVolume = osClient.blockStorage().volumes().get(resource.getReference());
    if (osVolume != null && context.isBuild()) {
        Status volumeStatus = osVolume.getStatus();
        if (Status.ERROR == volumeStatus || Status.ERROR_DELETING == volumeStatus || Status.ERROR_RESTORING == osVolume.getStatus()) {
            throw new OpenStackResourceException("Volume in failed state", resource.getType(), resource.getName(), cloudContext.getId(), volumeStatus.name());
        }
        return volumeStatus == Status.AVAILABLE;
    } else {
        return osVolume == null && !context.isBuild();
    }
}
Also used : Status(org.openstack4j.model.storage.block.Volume.Status) Volume(org.openstack4j.model.storage.block.Volume) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)

Aggregations

OpenStackResourceException (com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)18 OS4JException (org.openstack4j.api.exceptions.OS4JException)15 ActionResponse (org.openstack4j.model.common.ActionResponse)8 NeutronNetworkView (com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView)7 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)4 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)3 Server (org.openstack4j.model.compute.Server)2 Router (org.openstack4j.model.network.Router)2 State (org.openstack4j.model.network.State)2 Volume (org.openstack4j.model.storage.block.Volume)2 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)1 PortDefinition (com.sequenceiq.cloudbreak.cloud.model.PortDefinition)1 SecurityRule (com.sequenceiq.cloudbreak.cloud.model.SecurityRule)1 CinderVolumeView (com.sequenceiq.cloudbreak.cloud.openstack.view.CinderVolumeView)1 KeystoneCredentialView (com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView)1 NovaInstanceView (com.sequenceiq.cloudbreak.cloud.openstack.view.NovaInstanceView)1 ArrayList (java.util.ArrayList)1 Future (java.util.concurrent.Future)1 ComputeSecurityGroupService (org.openstack4j.api.compute.ComputeSecurityGroupService)1 BlockDeviceMappingCreate (org.openstack4j.model.compute.BlockDeviceMappingCreate)1