Search in sources :

Example 66 with Project

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

the class SuspendProjectCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
    CallContext.current().setEventDetails("Project Id: " + id);
    Project project = _projectService.suspendProject(id);
    if (project != null) {
        ProjectResponse response = _responseGenerator.createProjectResponse(project);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to suspend a project");
    }
}
Also used : Project(com.cloud.projects.Project) ProjectResponse(org.apache.cloudstack.api.response.ProjectResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 67 with Project

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

the class ActivateProjectCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    CallContext.current().setEventDetails("Project id: " + getId());
    Project project = _projectService.activateProject(getId());
    if (project != null) {
        ProjectResponse response = _responseGenerator.createProjectResponse(project);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to activate a project");
    }
}
Also used : Project(com.cloud.projects.Project) ProjectResponse(org.apache.cloudstack.api.response.ProjectResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 68 with Project

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

the class CreateProjectCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    Project project = _projectService.enableProject(this.getEntityId());
    if (project != null) {
        ProjectResponse response = _responseGenerator.createProjectResponse(project);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a project");
    }
}
Also used : Project(com.cloud.projects.Project) ProjectResponse(org.apache.cloudstack.api.response.ProjectResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 69 with Project

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

the class CreateSnapshotPolicyCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    Volume volume = _entityMgr.findById(Volume.class, getVolumeId());
    if (volume == null) {
        throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
    }
    Account account = _accountService.getAccount(volume.getAccountId());
    // Can create templates for enabled projects/accounts only
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
        Project project = _projectService.findByProjectAccountId(volume.getAccountId());
        if (project.getState() != Project.State.Active) {
            PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the specified project id in state=" + project.getState() + " as it's no longer active");
            ex.addProxyObject(project.getUuid(), "projectId");
            throw ex;
        }
    } else if (account.getState() == Account.State.disabled) {
        throw new PermissionDeniedException("The owner of template is disabled: " + account);
    }
    return volume.getAccountId();
}
Also used : Account(com.cloud.user.Account) Project(com.cloud.projects.Project) Volume(com.cloud.storage.Volume) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Example 70 with Project

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

the class CreateSnapshotFromVMSnapshotCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    VMSnapshot vmsnapshot = _entityMgr.findById(VMSnapshot.class, getVMSnapshotId());
    if (vmsnapshot == null) {
        throw new InvalidParameterValueException("Unable to find vmsnapshot by id=" + getVMSnapshotId());
    }
    Account account = _accountService.getAccount(vmsnapshot.getAccountId());
    // Can create templates for enabled projects/accounts only
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
        Project project = _projectService.findByProjectAccountId(vmsnapshot.getAccountId());
        if (project == null) {
            throw new InvalidParameterValueException("Unable to find project by account id=" + account.getUuid());
        }
        if (project.getState() != Project.State.Active) {
            throw new PermissionDeniedException("Can't add resources to the project id=" + project.getUuid() + " in state=" + project.getState() + " as it's no longer active");
        }
    } else if (account.getState() == Account.State.disabled) {
        throw new PermissionDeniedException("The owner of template is disabled: " + account);
    }
    return vmsnapshot.getAccountId();
}
Also used : Account(com.cloud.user.Account) Project(com.cloud.projects.Project) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot)

Aggregations

Project (com.cloud.projects.Project)89 Account (com.cloud.user.Account)55 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)28 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)27 Domain (com.cloud.domain.Domain)20 ArrayList (java.util.ArrayList)20 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)18 DomainVO (com.cloud.domain.DomainVO)12 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)11 Pair (com.cloud.utils.Pair)11 List (java.util.List)11 ServerApiException (com.cloud.api.ServerApiException)10 ProjectAccount (com.cloud.projects.ProjectAccount)10 Volume (com.cloud.storage.Volume)10 UserAccount (com.cloud.user.UserAccount)10 DB (com.cloud.utils.db.DB)10 ProjectResponse (com.cloud.api.response.ProjectResponse)9 Filter (com.cloud.utils.db.Filter)9 DataCenterVO (com.cloud.dc.DataCenterVO)8 VlanVO (com.cloud.dc.VlanVO)6