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;
}
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;
}
Aggregations