public Integer compareProject(ProjectVO db, net.juniper.contrail.api.types.Project vnc, StringBuffer syncLogMesg) { if (_manager.isSystemDefaultProject(db) && _manager.isSystemDefaultProject(vnc)) { return _manager.getProjectCanonicalName(db).compareTo(vnc.getName()); } else if (_manager.isSystemDefaultProject(db)) { return -1; } else if (_manager.isSystemDefaultProject(vnc)) { return 1; } return db.getUuid().compareTo(vnc.getUuid()); }
@Override public void createProject(ProjectVO db, StringBuffer syncLogMesg) throws IOException { final ApiConnector api = _manager.getApiConnector(); net.juniper.contrail.api.types.Project vnc = new net.juniper.contrail.api.types.Project(); vnc.setName(db.getName()); vnc.setUuid(db.getUuid()); if (!api.create(vnc)) { s_logger.error("Unable to create project: " + vnc.getName()); syncLogMesg.append("Error: Virtual project# VNC : Unable to create project: " + vnc.getName() + "\n"); return; } syncLogMesg.append("Project# VNC: " + vnc.getName() + " created \n"); }
public void onProjectCreate(String subject, String topic, org.apache.cloudstack.framework.events.Event event) { s_logger.info("onProjectCreate; topic: " + topic + "; subject: " + subject); try { long id = parseForId(event.getResourceType(), event.getDescription()); if (id != 0) { ProjectVO project = _projectDao.findById(id); if (project != null) { s_logger.info("createProject for name: " + project.getName() + "; uuid: " + project.getUuid()); StringBuffer logMesg = new StringBuffer(); _dbSync.createProject(project, logMesg); } else { /* could not find db record, resync complete class */ _dbSync.syncClass(net.juniper.contrail.api.types.Project.class); } } else { /* Unknown id, resync complete class */ _dbSync.syncClass(net.juniper.contrail.api.types.Project.class); } } catch (Exception e) { s_logger.info(e); } }
@Override public String getProjectId(long domainId, long accountId) throws IOException { ProjectVO project = getProject(accountId); if (project != null) { return project.getUuid(); } DomainVO domain = _domainDao.findById(domainId); if (domain.getId() != Domain.ROOT_DOMAIN) { net.juniper.contrail.api.types.Domain vncDomain = (net.juniper.contrail.api.types.Domain)_api.findById(net.juniper.contrail.api.types.Domain.class, domain.getUuid()); return _api.findByName(net.juniper.contrail.api.types.Project.class, vncDomain, VNC_DEFAULT_PROJECT); } return null; }
@Override @ActionEvent(eventType = EventTypes.EVENT_PROJECT_SUSPEND, eventDescription = "suspending project", async = true) public Project suspendProject(long projectId) throws ConcurrentOperationException, ResourceUnavailableException { Account caller = CallContext.current().getCallingAccount(); ProjectVO project = getProject(projectId); //verify input parameters if (project == null) { InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id"); ex.addProxyObject(String.valueOf(projectId), "projectId"); throw ex; } _accountMgr.checkAccess(caller, AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId())); if (suspendProject(project)) { s_logger.debug("Successfully suspended project id=" + projectId); return _projectDao.findById(projectId); } else { CloudRuntimeException ex = new CloudRuntimeException("Failed to suspend project with specified id"); ex.addProxyObject(project.getUuid(), "projectId"); throw ex; } }