Search in sources :

Example 1 with ServiceInstanceModel

use of org.apache.cloudstack.network.contrail.model.ServiceInstanceModel 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 2 with ServiceInstanceModel

use of org.apache.cloudstack.network.contrail.model.ServiceInstanceModel in project cloudstack by apache.

the class ModelDatabase method lookupServiceInstance.

public ServiceInstanceModel lookupServiceInstance(String fqn) {
    ServiceInstanceModel siKey = new ServiceInstanceModel(fqn);
    ServiceInstanceModel current = _serviceInstanceTable.ceiling(siKey);
    if (current != null && current.getQualifiedName().equals(fqn)) {
        return current;
    }
    return null;
}
Also used : ServiceInstanceModel(org.apache.cloudstack.network.contrail.model.ServiceInstanceModel)

Aggregations

ServiceInstanceModel (org.apache.cloudstack.network.contrail.model.ServiceInstanceModel)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 IOException (java.io.IOException)1 ApiConnector (net.juniper.contrail.api.ApiConnector)1 ServiceInstance (net.juniper.contrail.api.types.ServiceInstance)1 VirtualMachineModel (org.apache.cloudstack.network.contrail.model.VirtualMachineModel)1 VirtualNetworkModel (org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)1