All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openstack4j.openstack.magnum.internal.MagnumServiceImpl Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
package org.openstack4j.openstack.magnum.internal;


import static com.google.common.base.Preconditions.checkNotNull;
import static org.openstack4j.core.transport.ClientConstants.*;


import org.openstack4j.api.types.ServiceType;


import java.util.List;

import org.openstack4j.api.magnum.MagnumService;
import org.openstack4j.model.common.ActionResponse;
import org.openstack4j.model.magnum.Bay;
import org.openstack4j.model.magnum.Baymodel;
import org.openstack4j.model.magnum.Carequest;
import org.openstack4j.model.magnum.Certificate;
import org.openstack4j.model.magnum.Cluster;
import org.openstack4j.model.magnum.Clustertemplate;
import org.openstack4j.model.magnum.Container;
import org.openstack4j.model.magnum.Mservice;
import org.openstack4j.model.magnum.Pod;
import org.openstack4j.openstack.internal.BaseOpenStackService;
import org.openstack4j.openstack.magnum.MagnumBay;
import org.openstack4j.openstack.magnum.MagnumBay.BayConcreteBuilder.Bays;
import org.openstack4j.openstack.magnum.MagnumBaymodel;
import org.openstack4j.openstack.magnum.MagnumBaymodel.Baymodels;
import org.openstack4j.openstack.magnum.MagnumCertificate;
import org.openstack4j.openstack.magnum.MagnumCluster;
import org.openstack4j.openstack.magnum.MagnumCluster.Clusters;
import org.openstack4j.openstack.magnum.MagnumClustertemplate;
import org.openstack4j.openstack.magnum.MagnumClustertemplate.Clustertemplates;
import org.openstack4j.openstack.magnum.MagnumContainer;
import org.openstack4j.openstack.magnum.MagnumContainer.Containers;
import org.openstack4j.openstack.magnum.MagnumMservice.Mservices;
import org.openstack4j.openstack.magnum.MagnumPod;
import org.openstack4j.openstack.magnum.MagnumPod.Pods;


/**
 * OpenStack Container Infrastructure Management service (Magnum) APIs
 * 
 * @author Sohan Sangwan
 *
 */
public class MagnumServiceImpl extends BaseOpenStackService implements MagnumService {

    /**
     * Lists Magnum Services
     */
    @Override
    public List listMservices() {
        return get(Mservices.class, uri(MAGNUM_MSERVICES)).serviceType(ServiceType.MAGNUM).execute().getList();
    }

    @Override
    public List listBaymodels() {
        return get(Baymodels.class, uri(MAGNUM_BAYMODELS)).serviceType(ServiceType.MAGNUM).execute().getList();
    }

    @Override
    public Baymodel createBaymodel(Baymodel baymodel) {
        checkNotNull(baymodel);
        return post(MagnumBaymodel.class, MAGNUM_BAYMODELS).serviceType(ServiceType.MAGNUM).entity(baymodel).execute();
    }

    @Override
    public ActionResponse deleteBaymodel(String id) {
        checkNotNull(id);
        return deleteWithResponse(MAGNUM_BAYMODELS, "/", id).serviceType(ServiceType.MAGNUM).execute();
    }

    @Override
    public Baymodel showBaymodel(String id) {
        checkNotNull(id);
        return get(MagnumBaymodel.class, MAGNUM_BAYMODELS, "/", id).serviceType(ServiceType.MAGNUM).execute();
    }
    
    @Override
    public Baymodel updateBaymodel(String id, String operations) {
        checkNotNull(id);       
        checkNotNull(operations);
        return patch(MagnumBaymodel.class, MAGNUM_BAYMODELS, "/", id).serviceType(ServiceType.MAGNUM).json(operations).execute();        
    }

    @Override
    public List listBays() {
        return get(Bays.class, uri(MAGNUM_BAYS)).serviceType(ServiceType.MAGNUM).execute().getList();
    }

    @Override
    public Bay createBay(Bay bay) {
        checkNotNull(bay);
        return post(MagnumBay.class, MAGNUM_BAYS).serviceType(ServiceType.MAGNUM).entity(bay).execute();
    }

    @Override
    public ActionResponse deleteBay(String id) {
        checkNotNull(id);
        return deleteWithResponse(MAGNUM_BAYS, "/", id).serviceType(ServiceType.MAGNUM).execute();
    }
    
    @Override
    public Bay showBay(String id) {
        checkNotNull(id);
        return get(MagnumBay.class, MAGNUM_BAYS, "/", id).serviceType(ServiceType.MAGNUM).execute();
    }
    
    @Override
    public Bay updateBay(String id, String operations) {
        checkNotNull(id);       
        checkNotNull(operations);
        return patch(MagnumBay.class, MAGNUM_BAYS, "/", id).serviceType(ServiceType.MAGNUM).json(operations).execute();        
    }

    //Containers
    @Override
    public List listContainers() {
        return get(Containers.class, uri(MAGNUM_CONTAINERS)).serviceType(ServiceType.MAGNUM).execute().getList();
    }
    
    @Override
    public Container createContainer(Container container) {
        checkNotNull(container);
        return post(MagnumContainer.class, MAGNUM_CONTAINERS).serviceType(ServiceType.MAGNUM).entity(container).execute();
    }
    
    @Override
    public ActionResponse deleteContainer(String uuid) {
        checkNotNull(uuid);
        return deleteWithResponse(MAGNUM_CONTAINERS, "/", uuid).serviceType(ServiceType.MAGNUM).execute();
    }
    
    @Override
    public String execCmdInContainer(String id, String cmd) {
        checkNotNull(id);
        checkNotNull(cmd);
        ///v1/containers/%s/execute?command=ls
        return put(String.class, uri("%s/execute?command=%s", MAGNUM_CONTAINERS, id, cmd)).serviceType(ServiceType.MAGNUM).execute();
 
    }
    
    @Override
    public String getContainerLogs(String id) {
        checkNotNull(id);
        return get(String.class, uri("%s/%s/logs", MAGNUM_CONTAINERS, id)).serviceType(ServiceType.MAGNUM).execute();
    }

    @Override
    public Container pauseContainer(String id) {
        checkNotNull(id);
        return put(MagnumContainer.class, uri("%s/%s/pause", MAGNUM_CONTAINERS, id)).serviceType(ServiceType.MAGNUM).execute();
    }
    
    @Override
    public Container unpauseContainer(String id) {
        checkNotNull(id);
        return put(MagnumContainer.class, uri("%s/%s/unpause", MAGNUM_CONTAINERS, id)).serviceType(ServiceType.MAGNUM).execute();
    }
    
    @Override
    public Container rebootContainer(String id) {
        checkNotNull(id);
        return put(MagnumContainer.class, uri("%s/%s/reboot", MAGNUM_CONTAINERS, id)).serviceType(ServiceType.MAGNUM).execute();  
    }
    
    @Override
    public Container startContainer(String id) {
        checkNotNull(id);
        return put(MagnumContainer.class, uri("%s/%s/start", MAGNUM_CONTAINERS, id)).serviceType(ServiceType.MAGNUM).execute();  
    }
    
    @Override
    public Container stopContainer(String id) {
        checkNotNull(id);
        return put(MagnumContainer.class, uri("%s/%s/stop", MAGNUM_CONTAINERS, id)).serviceType(ServiceType.MAGNUM).execute();  
    }
    
    @Override
    public Container showContainer(String id) {
        checkNotNull(id);
        return get(MagnumContainer.class, uri("%s/%s", MAGNUM_CONTAINERS, id)).serviceType(ServiceType.MAGNUM).execute();
    }
    
    @Override
    public Container updateContainer(String id, String operations) {
        checkNotNull(id);       
        checkNotNull(operations);
        return patch(MagnumContainer.class, MAGNUM_CONTAINERS, "/", id).serviceType(ServiceType.MAGNUM).json(operations).execute();       
    
    }

    @Override
    public Certificate getCertificate(String uuid) {
        checkNotNull(uuid);
        return get(MagnumCertificate.class, uri("%s/%s", MAGNUM_CERTIFICATES, uuid)).serviceType(ServiceType.MAGNUM).execute();
    }

    @Override
    public Certificate signCertificate(Carequest ca) {
        checkNotNull(ca);
        return post(MagnumCertificate.class, MAGNUM_CERTIFICATES).serviceType(ServiceType.MAGNUM).entity(ca).execute();        
    }

    @Override
    public ActionResponse rotateCertificate(String uuid) {
        checkNotNull(uuid);
        return patch(ActionResponse.class, uri("%s/%s", MAGNUM_CERTIFICATES, uuid)).serviceType(ServiceType.MAGNUM).execute();
    }
    
    //Clusters

    @Override
    public Cluster createCluster(Cluster cluster) {
        checkNotNull(cluster);
        return post(MagnumCluster.class, MAGNUM_CLUSTERS).serviceType(ServiceType.MAGNUM).entity(cluster).execute();        
    }

    @Override
    public List listClusters() {
        return get(Clusters.class, uri(MAGNUM_CLUSTERS)).serviceType(ServiceType.MAGNUM).execute().getList();
    }

    @Override
    public Cluster showCluster(String id) {
        checkNotNull(id);
        return get(Cluster.class, uri("%s/%s", MAGNUM_CLUSTERS, id)).serviceType(ServiceType.MAGNUM).execute();
    }

    @Override
    public ActionResponse deleteCluster(String id) {
        checkNotNull(id);
        return deleteWithResponse(MAGNUM_CLUSTERS, "/", id).serviceType(ServiceType.MAGNUM).execute();
    }

    @Override
    public Cluster updateCluster(String id, String operations) {
        checkNotNull(id);       
        checkNotNull(operations);
        return patch(MagnumCluster.class, MAGNUM_CLUSTERS, "/", id).serviceType(ServiceType.MAGNUM).json(operations).execute();        
    }
    
    //Cluster template APIs

    @Override
    public Clustertemplate createClustertemplate(Clustertemplate template) {
        checkNotNull(template);
        return post(MagnumClustertemplate.class, MAGNUM_CLUSTERTEMPLATES).serviceType(ServiceType.MAGNUM).entity(template).execute();  
    }

    @Override
    public List listClustertemplate() {
        return get(Clustertemplates.class, uri(MAGNUM_CLUSTERTEMPLATES)).serviceType(ServiceType.MAGNUM).execute().getList();
    }

    @Override
    public ActionResponse deleteClustertemplate(String id) {
        checkNotNull(id);
        return deleteWithResponse(MAGNUM_CLUSTERTEMPLATES, "/", id).serviceType(ServiceType.MAGNUM).execute();
    }

    @Override
    public Clustertemplate updateClustertemplate(String id, String operations) {
        checkNotNull(id);       
        checkNotNull(operations);
        return patch(MagnumClustertemplate.class, MAGNUM_CLUSTERTEMPLATES, "/", id).serviceType(ServiceType.MAGNUM).json(operations).execute();        
    }

    @Override
    public List listPods(String bayUuid) {
        checkNotNull(bayUuid);
        // url: '/v1/pods/?bay_ident=%s'
        return get(Pods.class, uri("%s/?bay_ident=%s", MAGNUM_PODS, bayUuid)).serviceType(ServiceType.MAGNUM).execute().getList();
    }

    @Override
    public Pod createPod(Pod pod) {
        checkNotNull(pod);
        return post(MagnumPod.class, MAGNUM_PODS).serviceType(ServiceType.MAGNUM).entity(pod).execute();  
    }

    @Override
    public ActionResponse deletePod(String bayUuid, String id) {
        checkNotNull(bayUuid);
        checkNotNull(id);
        
        // Url: '/v1/pods/%s/?bay_ident=%s'
        return deleteWithResponse( uri("%s/%s/?bay_ident=%s", MAGNUM_PODS, id, bayUuid)).serviceType(ServiceType.MAGNUM).execute();
    }

    @Override
    public Pod showPod(String bayUuid, String id) {
        checkNotNull(bayUuid);   
        checkNotNull(id);
        
        // Url: '/v1/pods/%s/?bay_ident=%s'
        return get(MagnumPod.class, uri("%s/?bay_ident=%s", MAGNUM_PODS, bayUuid)).serviceType(ServiceType.MAGNUM).execute();        
    }

    @Override
    public Pod updatePod(String bayUuid, String id, String operations) {
        checkNotNull(id);       
        checkNotNull(operations);
        return patch(MagnumPod.class, MAGNUM_PODS, "/", id).serviceType(ServiceType.MAGNUM).json(operations).execute();        
    }



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy