Search in sources :

Example 1 with ProjectVO

use of com.cloud.projects.ProjectVO in project cloudstack by apache.

the class NetworkProviderTest method deleteProject.

public void deleteProject(String name) {
    BaseCmd cmd = new DeleteProjectCmd();
    BaseCmd proxy = ComponentContext.inject(cmd);
    ProjectVO project = _projectDao.findByNameAndDomain(name, Domain.ROOT_DOMAIN);
    try {
        ManagementServerMock.setParameter(proxy, "id", BaseCmd.CommandType.LONG, project.getId());
        ((DeleteProjectCmd) proxy).execute();
        if (_api.findById(net.juniper.contrail.api.types.Project.class, project.getUuid()) != null) {
            fail("unable to delete project in vnc");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception while deleting project");
    }
}
Also used : Project(net.juniper.contrail.api.types.Project) BaseCmd(org.apache.cloudstack.api.BaseCmd) DeleteProjectCmd(org.apache.cloudstack.api.command.user.project.DeleteProjectCmd) ProjectVO(com.cloud.projects.ProjectVO) CloudException(com.cloud.exception.CloudException) IOException(java.io.IOException)

Example 2 with ProjectVO

use of com.cloud.projects.ProjectVO in project cloudstack by apache.

the class ProjectDaoImpl method remove.

@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;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ProjectVO(com.cloud.projects.ProjectVO) DB(com.cloud.utils.db.DB)

Example 3 with ProjectVO

use of com.cloud.projects.ProjectVO in project cloudstack by apache.

the class DomainManagerImpl method cleanupDomain.

protected boolean cleanupDomain(Long domainId, Long ownerId) throws ConcurrentOperationException, ResourceUnavailableException {
    s_logger.debug("Cleaning up domain id=" + domainId);
    boolean success = true;
    DomainVO domainHandle = _domainDao.findById(domainId);
    {
        domainHandle.setState(Domain.State.Inactive);
        _domainDao.update(domainId, domainHandle);
        SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
        sc.addAnd("parent", SearchCriteria.Op.EQ, domainId);
        List<DomainVO> domains = _domainDao.search(sc, null);
        SearchCriteria<DomainVO> sc1 = _domainDao.createSearchCriteria();
        sc1.addAnd("path", SearchCriteria.Op.LIKE, "%" + "replace(" + domainHandle.getPath() + ", '%', '[%]')" + "%");
        List<DomainVO> domainsToBeInactivated = _domainDao.search(sc1, null);
        // update all subdomains to inactive so no accounts/users can be created
        for (DomainVO domain : domainsToBeInactivated) {
            domain.setState(Domain.State.Inactive);
            _domainDao.update(domain.getId(), domain);
        }
        // cleanup sub-domains first
        for (DomainVO domain : domains) {
            success = (success && cleanupDomain(domain.getId(), domain.getAccountId()));
            if (!success) {
                s_logger.warn("Failed to cleanup domain id=" + domain.getId());
            }
        }
    }
    // delete users which will also delete accounts and release resources for those accounts
    SearchCriteria<AccountVO> sc = _accountDao.createSearchCriteria();
    sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
    List<AccountVO> accounts = _accountDao.search(sc, null);
    for (AccountVO account : accounts) {
        if (account.getType() != Account.ACCOUNT_TYPE_PROJECT) {
            s_logger.debug("Deleting account " + account + " as a part of domain id=" + domainId + " cleanup");
            boolean deleteAccount = _accountMgr.deleteAccount(account, CallContext.current().getCallingUserId(), getCaller());
            if (!deleteAccount) {
                s_logger.warn("Failed to cleanup account id=" + account.getId() + " as a part of domain cleanup");
            }
            success = (success && deleteAccount);
        } else {
            ProjectVO project = _projectDao.findByProjectAccountId(account.getId());
            s_logger.debug("Deleting project " + project + " as a part of domain id=" + domainId + " cleanup");
            boolean deleteProject = _projectMgr.deleteProject(getCaller(), CallContext.current().getCallingUserId(), project);
            if (!deleteProject) {
                s_logger.warn("Failed to cleanup project " + project + " as a part of domain cleanup");
            }
            success = (success && deleteProject);
        }
    }
    //delete the domain shared networks
    boolean networksDeleted = true;
    s_logger.debug("Deleting networks for domain id=" + domainId);
    List<Long> networkIds = _networkDomainDao.listNetworkIdsByDomain(domainId);
    CallContext ctx = CallContext.current();
    ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(ctx.getCallingUserId()), ctx.getCallingAccount());
    for (Long networkId : networkIds) {
        s_logger.debug("Deleting network id=" + networkId + " as a part of domain id=" + domainId + " cleanup");
        if (!_networkMgr.destroyNetwork(networkId, context, false)) {
            s_logger.warn("Unable to destroy network id=" + networkId + " as a part of domain id=" + domainId + " cleanup.");
            networksDeleted = false;
        } else {
            s_logger.debug("Network " + networkId + " successfully deleted as a part of domain id=" + domainId + " cleanup.");
        }
    }
    //don't proceed if networks failed to cleanup. The cleanup will be performed for inactive domain once again
    if (!networksDeleted) {
        s_logger.debug("Failed to delete the shared networks as a part of domain id=" + domainId + " clenaup");
        return false;
    }
    // don't remove the domain if there are accounts required cleanup
    boolean deleteDomainSuccess = true;
    List<AccountVO> accountsForCleanup = _accountDao.findCleanupsForRemovedAccounts(domainId);
    if (accountsForCleanup.isEmpty()) {
        //release dedication if any, before deleting the domain
        List<DedicatedResourceVO> dedicatedResources = _dedicatedDao.listByDomainId(domainId);
        if (dedicatedResources != null && !dedicatedResources.isEmpty()) {
            s_logger.debug("Releasing dedicated resources for domain" + domainId);
            for (DedicatedResourceVO dr : dedicatedResources) {
                if (!_dedicatedDao.remove(dr.getId())) {
                    s_logger.warn("Fail to release dedicated resources for domain " + domainId);
                    return false;
                }
            }
        }
        //delete domain
        _messageBus.publish(_name, MESSAGE_PRE_REMOVE_DOMAIN_EVENT, PublishScope.LOCAL, domainHandle);
        deleteDomainSuccess = _domainDao.remove(domainId);
        _messageBus.publish(_name, MESSAGE_REMOVE_DOMAIN_EVENT, PublishScope.LOCAL, domainHandle);
        // Delete resource count and resource limits entries set for this domain (if there are any).
        _resourceCountDao.removeEntriesByOwner(domainId, ResourceOwnerType.Domain);
        _resourceLimitDao.removeEntriesByOwner(domainId, ResourceOwnerType.Domain);
    } else {
        s_logger.debug("Can't delete the domain yet because it has " + accountsForCleanup.size() + "accounts that need a cleanup");
        return false;
    }
    return success && deleteDomainSuccess;
}
Also used : CallContext(org.apache.cloudstack.context.CallContext) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) SearchCriteria(com.cloud.utils.db.SearchCriteria) ProjectVO(com.cloud.projects.ProjectVO) ReservationContext(com.cloud.vm.ReservationContext) DomainVO(com.cloud.domain.DomainVO) List(java.util.List) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO)

Example 4 with ProjectVO

use of com.cloud.projects.ProjectVO in project cloudstack by apache.

the class ContrailManagerImpl method getProjectId.

@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;
}
Also used : DomainVO(com.cloud.domain.DomainVO) Domain(com.cloud.domain.Domain) ProjectVO(com.cloud.projects.ProjectVO)

Example 5 with ProjectVO

use of com.cloud.projects.ProjectVO in project cloudstack by apache.

the class ServerEventHandlerImpl method onProjectCreate.

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);
    }
}
Also used : ProjectVO(com.cloud.projects.ProjectVO)

Aggregations

ProjectVO (com.cloud.projects.ProjectVO)5 DomainVO (com.cloud.domain.DomainVO)2 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)1 Domain (com.cloud.domain.Domain)1 CloudException (com.cloud.exception.CloudException)1 DB (com.cloud.utils.db.DB)1 SearchCriteria (com.cloud.utils.db.SearchCriteria)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 ReservationContext (com.cloud.vm.ReservationContext)1 ReservationContextImpl (com.cloud.vm.ReservationContextImpl)1 IOException (java.io.IOException)1 List (java.util.List)1 Project (net.juniper.contrail.api.types.Project)1 BaseCmd (org.apache.cloudstack.api.BaseCmd)1 DeleteProjectCmd (org.apache.cloudstack.api.command.user.project.DeleteProjectCmd)1 CallContext (org.apache.cloudstack.context.CallContext)1