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