Search in sources :

Example 1 with ServiceInstance

use of net.juniper.contrail.api.types.ServiceInstance in project cloudstack by apache.

the class VirtualMachineModel method buildServiceInstance.

/**
     * Link the virtual machine with the service instance when recovering state from database.
     *
     * @param controller
     * @param serviceUuid
     */
private void buildServiceInstance(ModelController controller, String serviceUuid) {
    ContrailManager manager = controller.getManager();
    ApiConnector api = controller.getApiAccessor();
    _serviceUuid = serviceUuid;
    ServiceInstance siObj;
    try {
        siObj = (ServiceInstance) api.findById(ServiceInstance.class, serviceUuid);
    } catch (IOException ex) {
        s_logger.warn("service-instance read", ex);
        throw new CloudRuntimeException("Unable to read service-instance object", ex);
    }
    ServiceInstanceModel siModel;
    String fqn = StringUtils.join(siObj.getQualifiedName(), ':');
    siModel = manager.getDatabase().lookupServiceInstance(fqn);
    if (siModel == null) {
        siModel = new ServiceInstanceModel(serviceUuid);
        siModel.build(controller, siObj);
        manager.getDatabase().getServiceInstances().add(siModel);
    }
    /*
         * The code that was under the ELSE was never executed and due to that has been removed.
         * Also, in the case siObj was null, it was going pass it as parameter to the build() method in the
         * siModel object.
         */
    _serviceModel = siModel;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ApiConnector(net.juniper.contrail.api.ApiConnector) ContrailManager(org.apache.cloudstack.network.contrail.management.ContrailManager) ServiceInstance(net.juniper.contrail.api.types.ServiceInstance) IOException(java.io.IOException)

Example 2 with ServiceInstance

use of net.juniper.contrail.api.types.ServiceInstance in project cloudstack by apache.

the class ServiceManagerImpl method createServiceInstance.

@Override
public ServiceVirtualMachine createServiceInstance(DataCenter zone, Account owner, VirtualMachineTemplate template, ServiceOffering serviceOffering, String name, Network left, Network right) {
    s_logger.debug("createServiceInstance by " + owner.getAccountName());
    // service instances need to be able to access the public network.
    if (left.getTrafficType() == TrafficType.Guest) {
        _networkModel.checkNetworkPermissions(owner, left);
    }
    if (right.getTrafficType() == TrafficType.Guest) {
        _networkModel.checkNetworkPermissions(owner, right);
    }
    final ApiConnector api = _manager.getApiConnector();
    VirtualNetworkModel leftModel = _manager.getDatabase().lookupVirtualNetwork(left.getUuid(), _manager.getCanonicalName(left), left.getTrafficType());
    if (leftModel == null) {
        throw new CloudRuntimeException("Unable to read virtual-network object");
    }
    VirtualNetworkModel rightModel = _manager.getDatabase().lookupVirtualNetwork(right.getUuid(), _manager.getCanonicalName(right), right.getTrafficType());
    if (rightModel == null) {
        throw new CloudRuntimeException("Unable to read virtual-network object");
    }
    net.juniper.contrail.api.types.Project project;
    try {
        project = _manager.getVncProject(owner.getDomainId(), owner.getAccountId());
    } catch (IOException ex) {
        s_logger.warn("read project", ex);
        throw new CloudRuntimeException(ex);
    }
    try {
        final String srvid = api.findByName(ServiceInstance.class, project, name);
        if (srvid != null) {
            throw new InvalidParameterValueException("service-instance " + name + " already exists uuid=" + srvid);
        }
    } catch (IOException ex) {
        s_logger.warn("service-instance lookup", ex);
        throw new CloudRuntimeException(ex);
    }
    // 1. Create service-instance.
    ServiceInstanceModel serviceModel = new ServiceInstanceModel(project, name, template, serviceOffering, leftModel, rightModel);
    try {
        serviceModel.update(_manager.getModelController());
    } catch (Exception ex) {
        s_logger.warn("service-instance update", ex);
        throw new CloudRuntimeException(ex);
    }
    s_logger.debug("service-instance object created");
    ServiceInstance siObj;
    try {
        _manager.getDatabase().getServiceInstances().add(serviceModel);
        siObj = serviceModel.getServiceInstance();
    } catch (Exception ex) {
        s_logger.warn("DB add", ex);
        throw new CloudRuntimeException(ex);
    }
    // 2. Create one virtual-machine.
    String svmName = name.replace(" ", "_") + "-1";
    ServiceVirtualMachine svm = createServiceVM(zone, owner, template, serviceOffering, svmName, siObj, left, right);
    s_logger.debug("created VMInstance " + svm.getUuid());
    // 3. Create the virtual-machine model and push the update.
    VirtualMachineModel instanceModel = new VirtualMachineModel(svm, svm.getUuid());
    _manager.getDatabase().getVirtualMachines().add(instanceModel);
    try {
        instanceModel.setServiceInstance(_manager.getModelController(), svm, serviceModel);
        instanceModel.update(_manager.getModelController());
    } catch (Exception ex) {
        s_logger.warn("service virtual-machine update", ex);
        throw new CloudRuntimeException(ex);
    }
    return svm;
}
Also used : ServiceInstanceModel(org.apache.cloudstack.network.contrail.model.ServiceInstanceModel) ApiConnector(net.juniper.contrail.api.ApiConnector) VirtualMachineModel(org.apache.cloudstack.network.contrail.model.VirtualMachineModel) ServiceInstance(net.juniper.contrail.api.types.ServiceInstance) IOException(java.io.IOException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 3 with ServiceInstance

use of net.juniper.contrail.api.types.ServiceInstance in project cloudstack by apache.

the class ServiceInstanceModel method createServiceInstance.

private ServiceInstance createServiceInstance(ModelController controller) {
    Project project = null;
    if (_projectId != null) {
        try {
            ApiConnector api = controller.getApiAccessor();
            project = (Project) api.findById(Project.class, _projectId);
        } catch (IOException ex) {
            s_logger.warn("project read", ex);
            throw new CloudRuntimeException("Unable to create service-instance object", ex);
        }
    }
    ServiceInstance si_obj = new ServiceInstance();
    if (project != null) {
        si_obj.setParent(project);
    }
    si_obj.setName(getName());
    si_obj.setServiceTemplate(_tmpl);
    si_obj.setProperties(new ServiceInstanceType(false, _mgmtName, _leftName, null, _rightName, null, new ServiceInstanceType.ServiceScaleOutType(1, false)));
    try {
        ApiConnector api = controller.getApiAccessor();
        api.create(si_obj);
    } catch (IOException ex) {
        s_logger.warn("service-instance create", ex);
        throw new CloudRuntimeException("Unable to create service-instance object", ex);
    }
    return si_obj;
}
Also used : Project(net.juniper.contrail.api.types.Project) ServiceInstanceType(net.juniper.contrail.api.types.ServiceInstanceType) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ApiConnector(net.juniper.contrail.api.ApiConnector) ServiceInstance(net.juniper.contrail.api.types.ServiceInstance) IOException(java.io.IOException)

Example 4 with ServiceInstance

use of net.juniper.contrail.api.types.ServiceInstance in project cloudstack by apache.

the class ServerDBSyncImpl method syncServiceInstance.

/**
     * The service-instance model list is build as a result of synchronizing virtual-machines.
     * @return
     */
public boolean syncServiceInstance() {
    final ApiConnector api = _manager.getApiConnector();
    boolean inSync;
    try {
        @SuppressWarnings("unchecked") List<ServiceInstance> siList = (List<ServiceInstance>) api.list(ServiceInstance.class, null);
        java.util.Collections.sort(siList, new ServiceInstanceComparator());
        DBSyncGeneric.SyncStats stats = new DBSyncGeneric.SyncStats();
        _dbSync.syncCollections(ServiceInstance.class, _manager.getDatabase().getServiceInstances(), siList, _rwMode, stats);
        inSync = stats.create == 0 && stats.delete == 0;
    } catch (Exception ex) {
        s_logger.warn("synchronize service-instances", ex);
        return false;
    }
    return inSync;
}
Also used : ApiConnector(net.juniper.contrail.api.ApiConnector) ServiceInstance(net.juniper.contrail.api.types.ServiceInstance) List(java.util.List) ArrayList(java.util.ArrayList) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)4 ApiConnector (net.juniper.contrail.api.ApiConnector)4 ServiceInstance (net.juniper.contrail.api.types.ServiceInstance)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Project (net.juniper.contrail.api.types.Project)1 ServiceInstanceType (net.juniper.contrail.api.types.ServiceInstanceType)1 ContrailManager (org.apache.cloudstack.network.contrail.management.ContrailManager)1 ServiceInstanceModel (org.apache.cloudstack.network.contrail.model.ServiceInstanceModel)1 VirtualMachineModel (org.apache.cloudstack.network.contrail.model.VirtualMachineModel)1 VirtualNetworkModel (org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)1