use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class DeleteNiciraNvpDeviceCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
final boolean result = niciraNvpElementService.deleteNiciraNvpDevice(this);
if (result) {
final SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Nicira device.");
}
} catch (final InvalidParameterValueException invalidParamExcp) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (final CloudRuntimeException runtimeExcp) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
use of com.cloud.utils.exception.InvalidParameterValueException 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());
}
}
use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class CloudStackImageStoreLifeCycleImpl method initialize.
@Override
public DataStore initialize(final Map<String, Object> dsInfos) {
final Long dcId = (Long) dsInfos.get("zoneId");
final String url = (String) dsInfos.get("url");
String name = (String) dsInfos.get("name");
if (name == null) {
name = url;
}
final String providerName = (String) dsInfos.get("providerName");
final DataStoreRole role = (DataStoreRole) dsInfos.get("role");
final Map<String, String> details = (Map<String, String>) dsInfos.get("details");
String logString = "";
if (url.contains("cifs")) {
logString = cleanPassword(url);
} else {
logString = StringUtils.cleanString(url);
}
s_logger.info("Trying to add a new data store at " + logString + " to data center " + dcId);
URI uri = null;
try {
uri = new URI(UriUtils.encodeURIComponent(url));
if (uri.getScheme() == null) {
throw new InvalidParameterValueException("uri.scheme is null " + StringUtils.cleanString(url) + ", add nfs:// (or cifs://) as a prefix");
} else if (uri.getScheme().equalsIgnoreCase("nfs")) {
if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("") || uri.getPath() == null || uri.getPath().equalsIgnoreCase("")) {
throw new InvalidParameterValueException("Your host and/or path is wrong. Make sure it's of the format nfs://hostname/path");
}
} else if (uri.getScheme().equalsIgnoreCase("cifs")) {
// Don't validate against a URI encoded URI.
final URI cifsUri = new URI(url);
final String warnMsg = UriUtils.getCifsUriParametersProblems(cifsUri);
if (warnMsg != null) {
throw new InvalidParameterValueException(warnMsg);
}
}
} catch (final URISyntaxException e) {
throw new InvalidParameterValueException(url + " is not a valid uri");
}
if (dcId == null) {
throw new InvalidParameterValueException("DataCenter id is null, and cloudstack default image store has to be associated with a data center");
}
final Map<String, Object> imageStoreParameters = new HashMap<>();
imageStoreParameters.put("name", name);
imageStoreParameters.put("zoneId", dcId);
imageStoreParameters.put("url", url);
imageStoreParameters.put("protocol", uri.getScheme().toLowerCase());
// default cloudstack provider only supports zone-wide image store
imageStoreParameters.put("scope", ScopeType.ZONE);
imageStoreParameters.put("providerName", providerName);
imageStoreParameters.put("role", role);
final ImageStoreVO ids = imageStoreHelper.createImageStore(imageStoreParameters, details);
return imageStoreMgr.getImageStore(ids.getId());
}
use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class AffinityGroupServiceImpl method createAffinityGroup.
@DB
@Override
public AffinityGroup createAffinityGroup(final String accountName, final Long projectId, final Long domainId, final String affinityGroupName, final String affinityGroupType, final String description) {
// validate the affinityGroupType
final Map<String, AffinityGroupProcessor> typeProcessorMap = getAffinityTypeToProcessorMap();
if (typeProcessorMap == null || typeProcessorMap.isEmpty()) {
throw new InvalidParameterValueException("Unable to create affinity group, no Affinity Group Types configured");
}
final AffinityGroupProcessor processor = typeProcessorMap.get(affinityGroupType);
if (processor == null) {
throw new InvalidParameterValueException("Unable to create affinity group, invalid affinity group type" + affinityGroupType);
}
final Account caller = CallContext.current().getCallingAccount();
if (processor.isAdminControlledGroup() && !_accountMgr.isRootAdmin(caller.getId())) {
throw new PermissionDeniedException("Cannot create the affinity group");
}
final ControlledEntity.ACLType aclType;
final Account owner;
boolean domainLevel = false;
if (projectId == null && domainId != null && accountName == null) {
verifyAccessToDomainWideProcessor(caller, processor);
final DomainVO domain = getDomain(domainId);
_accountMgr.checkAccess(caller, domain);
// domain level group, owner is SYSTEM.
owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
aclType = ControlledEntity.ACLType.Domain;
domainLevel = true;
} else {
owner = _accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
aclType = ControlledEntity.ACLType.Account;
}
verifyAffinityGroupNameInUse(owner.getAccountId(), owner.getDomainId(), affinityGroupName);
verifyDomainLevelAffinityGroupName(domainLevel, owner.getDomainId(), affinityGroupName);
final AffinityGroupVO group = createAffinityGroup(processor, owner, aclType, affinityGroupName, affinityGroupType, description, domainLevel, domainId);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Created affinity group =" + affinityGroupName);
}
return group;
}
use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method releasePublicIpRange.
@Override
@ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_RELEASE, eventDescription = "releasing a public ip range", async = false)
public boolean releasePublicIpRange(final ReleasePublicIpRangeCmd cmd) {
final Long vlanDbId = cmd.getId();
final VlanVO vlan = _vlanDao.findById(vlanDbId);
if (vlan == null) {
throw new InvalidParameterValueException("Please specify a valid IP range id.");
}
return releasePublicIpRange(vlanDbId, CallContext.current().getCallingUserId(), CallContext.current().getCallingAccount());
}
Aggregations