@Override public String getProjectCanonicalName(ProjectVO project) { return project.getName(); }
private boolean suspendProject(ProjectVO project) throws ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Marking project " + project + " with state " + State.Suspended + " as a part of project suspend..."); project.setState(State.Suspended); boolean updateResult = _projectDao.update(project.getId(), project); if (updateResult) { long projectAccountId = project.getProjectAccountId(); if (!_accountMgr.disableAccount(projectAccountId)) { s_logger.warn("Failed to suspend all project's " + project + " resources; the resources will be suspended later by background thread"); } } else { throw new CloudRuntimeException("Failed to mark the project " + project + " with state " + State.Suspended); } return true; }
@Override public void doInTransactionWithoutResult(TransactionStatus status) { project.setState(Project.State.Active); _projectDao.update(projectId, project); _accountMgr.enableAccount(project.getProjectAccountId()); } });
@Override public Boolean doInTransaction(TransactionStatus status) { s_logger.debug("Marking project id=" + project.getId() + " with state " + State.Disabled + " as a part of project delete..."); project.setState(State.Disabled); boolean updateResult = _projectDao.update(project.getId(), project); //owner can be already removed at this point, so adding the conditional check Account projectOwner = getProjectOwner(project.getId()); if (projectOwner != null) { _resourceLimitMgr.decrementResourceCount(projectOwner.getId(), ResourceType.project); } return updateResult; } });
protected ProjectDaoImpl() { AllFieldsSearch = createSearchBuilder(); AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), SearchCriteria.Op.EQ); AllFieldsSearch.and("domainId", AllFieldsSearch.entity().getDomainId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("projectAccountId", AllFieldsSearch.entity().getProjectAccountId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), SearchCriteria.Op.EQ); AllFieldsSearch.done(); CountByDomain = createSearchBuilder(Long.class); CountByDomain.select(null, Func.COUNT, null); CountByDomain.and("domainId", CountByDomain.entity().getDomainId(), SearchCriteria.Op.EQ); CountByDomain.done(); }
@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"); }
@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; } }
_accountMgr.checkAccess(caller, AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId())); Project.State currentState = project.getState();
for (ProjectVO project : inactiveProjects) { try { Account projectAccount = getAccount(project.getProjectAccountId()); if (projectAccount == null) { s_logger.debug("Removing inactive project id=" + project.getId()); _projectMgr.deleteProject(CallContext.current().getCallingAccount(), CallContext.current().getCallingUserId(), project); } else { s_logger.debug("Can't remove disabled project " + project + " as it has non removed account id=" + project.getId());
@Override public void doInTransactionWithoutResult(TransactionStatus status) throws ResourceAllocationException { if (displayText != null) { project.setDisplayText(displayText); _projectDao.update(projectId, project); Account futureOwnerAccount = _accountMgr.getActiveAccountByName(newOwnerName, project.getDomainId()); if (futureOwnerAccount == null) { throw new InvalidParameterValueException("Unable to find account name=" + newOwnerName + " in domain id=" + project.getDomainId());
@Override @ActionEvent(eventType = EventTypes.EVENT_PROJECT_DELETE, eventDescription = "deleting project", async = true) public boolean deleteProject(long projectId) { CallContext ctx = CallContext.current(); ProjectVO project = getProject(projectId); //verify input parameters if (project == null) { throw new InvalidParameterValueException("Unable to find project by id " + projectId); } _accountMgr.checkAccess(ctx.getCallingAccount(), AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId())); return deleteProject(ctx.getCallingAccount(), ctx.getCallingUserId(), project); }
@Override public Project doInTransaction(TransactionStatus status) { //Create an account associated with the project StringBuilder acctNm = new StringBuilder("PrjAcct-"); acctNm.append(name).append("-").append(ownerFinal.getDomainId()); Account projectAccount = _accountMgr.createAccount(acctNm.toString(), Account.ACCOUNT_TYPE_PROJECT, null, domainId, null, null, UUID.randomUUID().toString()); Project project = _projectDao.persist(new ProjectVO(name, displayText, ownerFinal.getDomainId(), projectAccount.getId())); //assign owner to the project assignAccountToProject(project, ownerFinal.getId(), ProjectAccount.Role.Admin); if (project != null) { CallContext.current().setEventDetails("Project id=" + project.getId()); CallContext.current().putContextParameter(Project.class, project.getUuid()); } //Increment resource count _resourceLimitMgr.incrementResourceCount(ownerFinal.getId(), ResourceType.project); return project; } });
@Override @DB public boolean remove(Long projectId) { boolean result = false; TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); ProjectVO projectToRemove = findById(projectId); projectToRemove.setName(null); if (!update(projectId, projectToRemove)) { s_logger.warn("Failed to reset name for the project id=" + projectId + " as a part of project remove"); return false; } _tagsDao.removeByIdAndType(projectId, ResourceObjectType.Project); result = super.remove(projectId); txn.commit(); return result; }
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 @ActionEvent(eventType = EventTypes.EVENT_PROJECT_CREATE, eventDescription = "creating project", async = true) @DB public Project enableProject(long projectId) { Account caller = CallContext.current().getCallingAccount(); ProjectVO project = getProject(projectId); //verify input parameters if (project == null) { throw new InvalidParameterValueException("Unable to find project by id " + projectId); } _accountMgr.checkAccess(caller, AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId())); //at this point enabling project doesn't require anything, so just update the state project.setState(State.Active); _projectDao.update(projectId, project); return project; }
_accountMgr.checkAccess(caller, AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId()));
public Boolean equalProject(ProjectVO db, net.juniper.contrail.api.types.Project vnc, StringBuffer syncLogMesg) { syncLogMesg.append("Project# DB: " + db.getName() + "; VNC: " + vnc.getName() + "; action: equal, no action\n"); return true; }
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()); }