use of com.cloud.projects.Project in project cloudstack by apache.
the class CreateSnapshotCmd 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) {
throw new PermissionDeniedException("Can't add resources to the project id=" + project.getId() + " 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 volume.getAccountId();
}
use of com.cloud.projects.Project in project cloudstack by apache.
the class CreateProjectCmd method create.
@Override
public void create() throws ResourceAllocationException {
CallContext.current().setEventDetails("Project Name: " + getName());
Project project = _projectService.createProject(getName(), getDisplayText(), getAccountName(), getDomainId());
if (project != null) {
this.setEntityId(project.getId());
this.setEntityUuid(project.getUuid());
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a project");
}
}
use of com.cloud.projects.Project in project cloudstack by apache.
the class UpdateProjectCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceAllocationException {
CallContext.current().setEventDetails("Project id: " + getId());
Project project = _projectService.updateProject(getId(), getDisplayText(), getAccountName());
if (project != null) {
ProjectResponse response = _responseGenerator.createProjectResponse(project);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update a project");
}
}
use of com.cloud.projects.Project in project cloudstack by apache.
the class ActionEventUtils method publishOnEventBus.
private static void publishOnEventBus(long userId, long accountId, String eventCategory, String eventType, Event.State state, String description) {
String configKey = Config.PublishActionEvent.key();
String value = s_configDao.getValue(configKey);
boolean configValue = Boolean.parseBoolean(value);
if (!configValue)
return;
try {
s_eventBus = ComponentContext.getComponent(EventBus.class);
} catch (NoSuchBeanDefinitionException nbe) {
// no provider is configured to provide events bus, so just return
return;
}
// get the entity details for which ActionEvent is generated
String entityType = null;
String entityUuid = null;
CallContext context = CallContext.current();
//Get entity Class(Example - VirtualMachine.class) from the event Type eg. - VM.CREATE
Class<?> entityClass = EventTypes.getEntityClassForEvent(eventType);
if (entityClass != null) {
//Get uuid from id
Object param = context.getContextParameter(entityClass);
if (param != null) {
try {
entityUuid = getEntityUuid(entityClass, param);
entityType = entityClass.getName();
} catch (Exception e) {
s_logger.debug("Caught exception while finding entityUUID, moving on");
}
}
}
org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event(ManagementService.Name, eventCategory, eventType, EventTypes.getEntityForEvent(eventType), entityUuid);
Map<String, String> eventDescription = new HashMap<String, String>();
Project project = s_projectDao.findByProjectAccountId(accountId);
Account account = s_accountDao.findById(accountId);
User user = s_userDao.findById(userId);
// if account has been deleted, this might be called during cleanup of resources and results in null pointer
if (account == null)
return;
if (user == null)
return;
if (project != null)
eventDescription.put("project", project.getUuid());
eventDescription.put("user", user.getUuid());
eventDescription.put("account", account.getUuid());
eventDescription.put("event", eventType);
eventDescription.put("status", state.toString());
eventDescription.put("entity", entityType);
eventDescription.put("entityuuid", entityUuid);
//Put all the first class entities that are touched during the action. For now atleast put in the vmid.
populateFirstClassEntities(eventDescription);
eventDescription.put("description", description);
String eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").format(new Date());
eventDescription.put("eventDateTime", eventDate);
event.setDescription(eventDescription);
try {
s_eventBus.publish(event);
} catch (EventBusException e) {
s_logger.warn("Failed to publish action event on the the event bus.");
}
}
use of com.cloud.projects.Project in project cloudstack by apache.
the class AddAccountToProjectCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
Project project = _projectService.getProject(getProjectId());
//verify input parameters
if (project == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified ID");
ex.addProxyObject(getProjectId().toString(), "projectId");
throw ex;
}
return _projectService.getProjectOwner(getProjectId()).getId();
}
Aggregations