Search in sources :

Example 66 with ListResponse

use of com.cloud.api.response.ListResponse in project cosmic by MissionCriticalCloud.

the class LdapImportUsersCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    List<LdapUser> users;
    try {
        if (StringUtils.isNotBlank(groupName)) {
            users = _ldapManager.getUsersInGroup(groupName);
        } else {
            users = _ldapManager.getUsers();
        }
    } catch (final NoLdapUserMatchingQueryException ex) {
        users = new ArrayList<>();
        s_logger.info("No Ldap user matching query. " + " ::: " + ex.getMessage());
    }
    final List<LdapUser> addedUsers = new ArrayList<>();
    for (final LdapUser user : users) {
        final Domain domain = getDomain(user);
        try {
            createCloudstackUserAccount(user, getAccountName(user), domain);
            addedUsers.add(user);
        } catch (final InvalidParameterValueException ex) {
            s_logger.error("Failed to create user with username: " + user.getUsername() + " ::: " + ex.getMessage());
        }
    }
    final ListResponse<LdapUserResponse> response = new ListResponse<>();
    response.setResponses(createLdapUserResponse(addedUsers));
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : NoLdapUserMatchingQueryException(com.cloud.ldap.NoLdapUserMatchingQueryException) LdapUser(com.cloud.ldap.LdapUser) ListResponse(com.cloud.api.response.ListResponse) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) Domain(com.cloud.domain.Domain) LdapUserResponse(com.cloud.api.response.LdapUserResponse)

Example 67 with ListResponse

use of com.cloud.api.response.ListResponse in project cosmic by MissionCriticalCloud.

the class DedicateZoneCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final List<? extends DedicatedResources> result = dedicatedService.dedicateZone(getZoneId(), getDomainId(), getAccountName());
    final ListResponse<DedicateZoneResponse> response = new ListResponse<>();
    final List<DedicateZoneResponse> zoneResponseList = new ArrayList<>();
    if (result != null) {
        for (final DedicatedResources resource : result) {
            final DedicateZoneResponse zoneresponse = dedicatedService.createDedicateZoneResponse(resource);
            zoneResponseList.add(zoneresponse);
        }
        response.setResponses(zoneResponseList);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate zone");
    }
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) DedicatedResources(com.cloud.dc.DedicatedResources) ArrayList(java.util.ArrayList) DedicateZoneResponse(com.cloud.api.response.DedicateZoneResponse)

Example 68 with ListResponse

use of com.cloud.api.response.ListResponse in project cosmic by MissionCriticalCloud.

the class ListDedicatedHostsCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////l
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final Pair<List<? extends DedicatedResourceVO>, Integer> result = dedicatedService.listDedicatedHosts(this);
    final ListResponse<DedicateHostResponse> response = new ListResponse<>();
    final List<DedicateHostResponse> Responses = new ArrayList<>();
    if (result != null) {
        for (final DedicatedResources resource : result.first()) {
            final DedicateHostResponse hostResponse = dedicatedService.createDedicateHostResponse(resource);
            Responses.add(hostResponse);
        }
        response.setResponses(Responses, result.second());
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to list dedicated hosts");
    }
}
Also used : DedicateHostResponse(com.cloud.api.response.DedicateHostResponse) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) DedicatedResources(com.cloud.dc.DedicatedResources) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO)

Example 69 with ListResponse

use of com.cloud.api.response.ListResponse in project cosmic by MissionCriticalCloud.

the class ListDedicatedPodsCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final Pair<List<? extends DedicatedResourceVO>, Integer> result = dedicatedService.listDedicatedPods(this);
    final ListResponse<DedicatePodResponse> response = new ListResponse<>();
    final List<DedicatePodResponse> Responses = new ArrayList<>();
    if (result != null) {
        for (final DedicatedResources resource : result.first()) {
            final DedicatePodResponse podresponse = dedicatedService.createDedicatePodResponse(resource);
            Responses.add(podresponse);
        }
        response.setResponses(Responses, result.second());
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to list dedicated pods");
    }
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) DedicatePodResponse(com.cloud.api.response.DedicatePodResponse) DedicatedResources(com.cloud.dc.DedicatedResources) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO)

Example 70 with ListResponse

use of com.cloud.api.response.ListResponse in project cosmic by MissionCriticalCloud.

the class ListNiciraNvpDevicesCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
    try {
        final List<NiciraNvpDeviceVO> niciraDevices = niciraNvpElementService.listNiciraNvpDevices(this);
        final ListResponse<NiciraNvpDeviceResponse> response = new ListResponse<>();
        final List<NiciraNvpDeviceResponse> niciraDevicesResponse = new ArrayList<>();
        if (niciraDevices != null && !niciraDevices.isEmpty()) {
            for (final NiciraNvpDeviceVO niciraDeviceVO : niciraDevices) {
                final NiciraNvpDeviceResponse niciraDeviceResponse = niciraNvpElementService.createNiciraNvpDeviceResponse(niciraDeviceVO);
                niciraDevicesResponse.add(niciraDeviceResponse);
            }
        }
        response.setResponses(niciraDevicesResponse);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } catch (final InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (final CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) NiciraNvpDeviceResponse(com.cloud.api.response.NiciraNvpDeviceResponse)

Aggregations

ListResponse (com.cloud.api.response.ListResponse)156 ArrayList (java.util.ArrayList)139 List (java.util.List)60 ServerApiException (com.cloud.api.ServerApiException)30 TemplateResponse (com.cloud.api.response.TemplateResponse)13 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)11 ResponseView (com.cloud.api.ResponseObject.ResponseView)10 Network (com.cloud.network.Network)9 DedicatedResources (com.cloud.dc.DedicatedResources)8 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)8 DomainResponse (com.cloud.api.response.DomainResponse)7 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)7 Domain (com.cloud.domain.Domain)7 VirtualMachine (com.cloud.vm.VirtualMachine)7 StoragePoolResponse (com.cloud.api.response.StoragePoolResponse)6 UserResponse (com.cloud.api.response.UserResponse)6 UserVmResponse (com.cloud.api.response.UserVmResponse)6 Host (com.cloud.host.Host)6 AccountResponse (com.cloud.api.response.AccountResponse)5 HostResponse (com.cloud.api.response.HostResponse)5