From eeb3f1725d7efa9b297360649707ca31c6ad0ca2 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Wed, 16 Jan 2013 15:06:27 -0800 Subject: [PATCH 1/5] CS-17074: cloudstack UI - Advanced SG-enabled zone - Infrastructure menu - create guest network - scope dropdown - add option "All". --- ui/scripts/system.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/scripts/system.js b/ui/scripts/system.js index 6733da1e2b9..bd8d3316103 100644 --- a/ui/scripts/system.js +++ b/ui/scripts/system.js @@ -1148,6 +1148,7 @@ var array1 = []; if(args.context.zones[0].networktype == "Advanced" && args.context.zones[0].securitygroupsenabled == true) { array1.push({id: 'account-specific', description: 'Account'}); + array1.push({id: 'zone-wide', description: 'All'}); } else { array1.push({id: 'zone-wide', description: 'All'}); From a22bfd7e7b412793e4a7cbb73f96b7ddfb6db887 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Wed, 16 Jan 2013 15:10:24 -0800 Subject: [PATCH 2/5] CLOUDSTACK-537: cloudstack UI - Advanced SG-enabled zone - VM Wizard - API has been chagned. Here is related UI change: not pass networkID to deployVirtualMachine API. --- ui/scripts/instanceWizard.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/scripts/instanceWizard.js b/ui/scripts/instanceWizard.js index 89ca1d63361..e4b1f31d427 100644 --- a/ui/scripts/instanceWizard.js +++ b/ui/scripts/instanceWizard.js @@ -545,7 +545,8 @@ if(checkedSecurityGroupIdArray.length > 0) array1.push("&securitygroupids=" + checkedSecurityGroupIdArray.join(",")); - + + /* if(selectedZoneObj.networktype == "Advanced" && selectedZoneObj.securitygroupsenabled == true) { // Advanced SG-enabled zone var networkData = { zoneId: selectedZoneObj.id, @@ -577,6 +578,8 @@ return; } } + */ + } else if (step5ContainerType == 'nothing-to-select') { if(args.context.networks != null) { //from VPC tier From 975021dda1aeee24c8729407e323a5e884e9ad31 Mon Sep 17 00:00:00 2001 From: Marcus Sorensen Date: Wed, 16 Jan 2013 17:43:35 -0700 Subject: [PATCH 3/5] Summary: adding resizeVolume api call Detail: This merges the resizevolume feature branch, which provides the ability to migrate a disk between disk offerings, thereby changing its size, or specifying a new size if current disk offering is custom. BUG-ID: CLOUDSTACK-644 Signed-off-by: Marcus Sorensen 1358358209 -0700 --- .../agent/api/storage/ResizeVolumeAnswer.java | 40 +++ .../api/storage/ResizeVolumeCommand.java | 86 ++++++ api/src/com/cloud/event/EventTypes.java | 1 + .../com/cloud/exception/CloudException.java | 1 - api/src/com/cloud/storage/StorageService.java | 10 + api/src/com/cloud/storage/Volume.java | 9 +- .../apache/cloudstack/api/ApiConstants.java | 1 + .../api/BaseUpdateTemplateOrIsoCmd.java | 0 ...BaseUpdateTemplateOrIsoPermissionsCmd.java | 0 .../command/user/volume/ResizeVolumeCmd.java | 153 +++++++++++ .../api/test/ResizeVolumeCommandTest.java | 199 ++++++++++++++ client/tomcatconf/commands.properties.in | 1 + .../resource/LibvirtComputingResource.java | 77 ++++++ .../xen/resource/CitrixResourceBase.java | 22 ++ scripts/storage/qcow2/resizevolume.sh | 253 ++++++++++++++++++ .../com/cloud/storage/StorageManagerImpl.java | 180 +++++++++++++ setup/db/create-schema-view.sql | 0 test/integration/smoke/test_volumes.py | 125 ++++++++- tools/marvin/marvin/integration/lib/base.py | 6 + 19 files changed, 1157 insertions(+), 7 deletions(-) create mode 100644 api/src/com/cloud/agent/api/storage/ResizeVolumeAnswer.java create mode 100644 api/src/com/cloud/agent/api/storage/ResizeVolumeCommand.java mode change 100755 => 100644 api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java mode change 100755 => 100644 api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java create mode 100644 api/src/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java create mode 100644 api/test/src/com/cloud/agent/api/test/ResizeVolumeCommandTest.java create mode 100644 scripts/storage/qcow2/resizevolume.sh mode change 100755 => 100644 setup/db/create-schema-view.sql diff --git a/api/src/com/cloud/agent/api/storage/ResizeVolumeAnswer.java b/api/src/com/cloud/agent/api/storage/ResizeVolumeAnswer.java new file mode 100644 index 00000000000..3434b985aaa --- /dev/null +++ b/api/src/com/cloud/agent/api/storage/ResizeVolumeAnswer.java @@ -0,0 +1,40 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.agent.api.storage; + +import com.cloud.agent.api.Answer; + +public class ResizeVolumeAnswer extends Answer { + private long newSize; + + protected ResizeVolumeAnswer() { + + } + + public ResizeVolumeAnswer(ResizeVolumeCommand cmd, boolean result, String details, long newSize) { + super(cmd, result, details); + this.newSize = newSize; + } + + public ResizeVolumeAnswer(ResizeVolumeCommand cmd, boolean result, String details) { + super(cmd, result, details); + } + + public long getNewSize() { + return newSize; + } +} diff --git a/api/src/com/cloud/agent/api/storage/ResizeVolumeCommand.java b/api/src/com/cloud/agent/api/storage/ResizeVolumeCommand.java new file mode 100644 index 00000000000..8af23a0ab81 --- /dev/null +++ b/api/src/com/cloud/agent/api/storage/ResizeVolumeCommand.java @@ -0,0 +1,86 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.agent.api.storage; + +import com.cloud.agent.api.Command; +import com.cloud.agent.api.to.StorageFilerTO; +import com.cloud.storage.StoragePool; + +public class ResizeVolumeCommand extends Command { + private String path; + private StorageFilerTO pool; + private String vmInstance; + private Long newSize; + private Long currentSize; + private boolean shrinkOk; + + protected ResizeVolumeCommand() { + + } + + public ResizeVolumeCommand(String path, + StorageFilerTO pool, + Long currentSize, + Long newSize, + boolean shrinkOk, + String vmInstance) + { + this.path = path; + this.pool = pool; + this.vmInstance = vmInstance; + this.currentSize = currentSize; + this.newSize = newSize; + this.shrinkOk = shrinkOk; + } + + public String getPath() { + return path; + } + + public String getPoolUuid() { + return pool.getUuid(); + } + + public StorageFilerTO getPool() { + return pool; + } + + public long getNewSize() { + return newSize; + } + + public long getCurrentSize() { + return currentSize; + } + + public boolean getShrinkOk() { + return shrinkOk; + } + + public String getInstanceName() { + return vmInstance; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean executeInSequence() { + return false; + } + +} diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index 8c622252d17..87eddca5a69 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -108,6 +108,7 @@ public class EventTypes { public static final String EVENT_VOLUME_EXTRACT = "VOLUME.EXTRACT"; public static final String EVENT_VOLUME_UPLOAD = "VOLUME.UPLOAD"; public static final String EVENT_VOLUME_MIGRATE = "VOLUME.MIGRATE"; + public static final String EVENT_VOLUME_RESIZE = "VOLUME.RESIZE"; // Domains public static final String EVENT_DOMAIN_CREATE = "DOMAIN.CREATE"; diff --git a/api/src/com/cloud/exception/CloudException.java b/api/src/com/cloud/exception/CloudException.java index 036cb1b8adc..732670288f1 100644 --- a/api/src/com/cloud/exception/CloudException.java +++ b/api/src/com/cloud/exception/CloudException.java @@ -54,7 +54,6 @@ public class CloudException extends Exception { return; } - public ArrayList getIdProxyList() { return idList; } diff --git a/api/src/com/cloud/storage/StorageService.java b/api/src/com/cloud/storage/StorageService.java index ff8ec13e33b..a06f2138042 100644 --- a/api/src/com/cloud/storage/StorageService.java +++ b/api/src/com/cloud/storage/StorageService.java @@ -23,6 +23,7 @@ import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaint import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd; import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd; import org.apache.cloudstack.api.command.user.volume.UploadVolumeCmd; +import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.PermissionDeniedException; @@ -70,6 +71,15 @@ public interface StorageService{ Volume createVolume(CreateVolumeCmd cmd); + /** + * Resizes the volume based on the given criteria + * + * @param cmd + * the API command wrapping the criteria + * @return the volume object + */ + Volume resizeVolume(ResizeVolumeCmd cmd); + /** * Delete the storage pool * diff --git a/api/src/com/cloud/storage/Volume.java b/api/src/com/cloud/storage/Volume.java index bfbd816d911..38ba2d413e0 100755 --- a/api/src/com/cloud/storage/Volume.java +++ b/api/src/com/cloud/storage/Volume.java @@ -36,6 +36,7 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, Ba Ready("The volume is ready to be used."), Migrating("The volume is migrating to other storage pool"), Snapshotting("There is a snapshot created on this volume, not backed up to secondary storage yet"), + Resizing("The volume is being resized"), Expunging("The volume is being expunging"), Destroy("The volume is destroyed, and can't be recovered."), UploadOp ("The volume upload operation is in progress or in short the volume is on secondary storage"); @@ -62,7 +63,10 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, Ba s_fsm.addTransition(Creating, Event.OperationFailed, Allocated); s_fsm.addTransition(Creating, Event.OperationSucceeded, Ready); s_fsm.addTransition(Creating, Event.DestroyRequested, Destroy); - s_fsm.addTransition(Creating, Event.CreateRequested, Creating); + s_fsm.addTransition(Creating, Event.CreateRequested, Creating); + s_fsm.addTransition(Ready, Event.ResizeRequested, Resizing); + s_fsm.addTransition(Resizing, Event.OperationSucceeded, Ready); + s_fsm.addTransition(Resizing, Event.OperationFailed, Ready); s_fsm.addTransition(Allocated, Event.UploadRequested, UploadOp); s_fsm.addTransition(UploadOp, Event.CopyRequested, Creating);// CopyRequested for volume from sec to primary storage s_fsm.addTransition(Creating, Event.CopySucceeded, Ready); @@ -92,7 +96,8 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, Ba MigrationRequested, SnapshotRequested, DestroyRequested, - ExpungingRequested; + ExpungingRequested, + ResizeRequested; } /** diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java index d3bfcd66afc..58a78318fae 100644 --- a/api/src/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/org/apache/cloudstack/api/ApiConstants.java @@ -387,6 +387,7 @@ public class ApiConstants { public static final String ESP_LIFETIME = "esplifetime"; public static final String DPD = "dpd"; public static final String FOR_VPC = "forvpc"; + public static final String SHRINK_OK = "shrinkok"; public static final String NICIRA_NVP_DEVICE_ID = "nvpdeviceid"; public static final String NICIRA_NVP_TRANSPORT_ZONE_UUID = "transportzoneuuid"; public static final String NICIRA_NVP_DEVICE_NAME = "niciradevicename"; diff --git a/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java b/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java old mode 100755 new mode 100644 diff --git a/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java b/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java old mode 100755 new mode 100644 diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java new file mode 100644 index 00000000000..e42bf3565cc --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java @@ -0,0 +1,153 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.volume; + +import org.apache.cloudstack.api.response.*; +import org.apache.log4j.Logger; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.BaseListTaggedResourcesCmd; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; +import java.util.regex.Matcher; + +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.PermissionDeniedException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.async.AsyncJob; +import com.cloud.event.EventTypes; +import com.cloud.projects.Project; +import com.cloud.storage.Volume; +import com.cloud.user.Account; +import com.cloud.user.UserContext; + + +@APICommand(name="resizeVolume", description="Resizes a volume", responseObject=VolumeResponse.class) +public class ResizeVolumeCmd extends BaseAsyncCmd { + public static final Logger s_logger = Logger.getLogger(ResizeVolumeCmd.class.getName()); + + private static final String s_name = "resizevolumeresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.ID, entityType=VolumeResponse.class, type=CommandType.UUID, description="the ID of the disk volume") + private Long id; + + @Parameter(name=ApiConstants.SIZE, type=CommandType.LONG, required=false, description="New volume size in G") + private Long size; + + @Parameter(name=ApiConstants.SHRINK_OK, type=CommandType.BOOLEAN, required=false, description="Verify OK to Shrink") + private boolean shrinkOk; + + @Parameter(name=ApiConstants.DISK_OFFERING_ID, entityType=DiskOfferingResponse.class, type=CommandType.UUID, required=false, description="new disk offering id") + private Long newDiskOfferingId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getEntityId() { + return id; + } + + public Long getSize() { + return size; + } + + public boolean getShrinkOk() { + return shrinkOk; + } + + public Long getNewDiskOfferingId() { + return newDiskOfferingId; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.Volume; + } + + public static String getResultObjectName() { + return "volume"; + } + + @Override + public long getEntityOwnerId() { + + Volume volume = _entityMgr.findById(Volume.class, getEntityId()); + if (volume == null) { + throw new InvalidParameterValueException("Unable to find volume by id=" + id); + } + + Account account = _accountService.getAccount(volume.getAccountId()); + //Can resize volumes 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 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 volume " + id + " is disabled: " + account); + } + + return volume.getAccountId(); + } + + + @Override + public String getEventType() { + return EventTypes.EVENT_VOLUME_RESIZE; + } + + @Override + public String getEventDescription() { + return "Volume Id: " + getEntityId() + " to size " + getSize() + "G" ; + } + + @Override + public void execute(){ + UserContext.current().setEventDetails("Volume Id: " + getEntityId() + " to size " + getSize() + "G"); + Volume volume = _storageService.resizeVolume(this); + if (volume != null) { + VolumeResponse response = _responseGenerator.createVolumeResponse(volume); + //FIXME - have to be moved to ApiResponseHelper + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to resize volume"); + } + } +} diff --git a/api/test/src/com/cloud/agent/api/test/ResizeVolumeCommandTest.java b/api/test/src/com/cloud/agent/api/test/ResizeVolumeCommandTest.java new file mode 100644 index 00000000000..2d248b2f53a --- /dev/null +++ b/api/test/src/com/cloud/agent/api/test/ResizeVolumeCommandTest.java @@ -0,0 +1,199 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package src.com.cloud.agent.api.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.junit.Test; + +import com.cloud.agent.api.storage.ResizeVolumeCommand; +import com.cloud.agent.api.to.StorageFilerTO; +import com.cloud.storage.StoragePool; +import com.cloud.storage.Storage.StoragePoolType; +import com.cloud.storage.StoragePoolStatus; + + +public class ResizeVolumeCommandTest { + + public StoragePool dummypool = new StoragePool() { + public long getId() { + return 1L; + }; + + public String getName() { + return "name"; + }; + + public String getUuid() { + return "bed9f83e-cac3-11e1-ac8a-0050568b007e"; + }; + + public StoragePoolType getPoolType() { + return StoragePoolType.Filesystem; + }; + + public Date getCreated() { + Date date = null; + try { + date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss") + .parse("01/01/1970 12:12:12"); + } catch (ParseException e) { + e.printStackTrace(); + } + return date; + } + + public Date getUpdateTime() { + return new Date(); + }; + + public long getDataCenterId() { + return 0L; + }; + + public long getCapacityBytes() { + return 0L; + }; + + public long getAvailableBytes() { + return 0L; + }; + + public Long getClusterId() { + return 0L; + }; + + public String getHostAddress() { + return "hostAddress"; + }; + + public String getPath() { + return "path"; + }; + + public String getUserInfo() { + return "userInfo"; + }; + + public boolean isShared() { + return false; + }; + + public boolean isLocal() { + return false; + }; + + public StoragePoolStatus getStatus() { + return StoragePoolStatus.Up; + }; + + public int getPort() { + return 25; + }; + + public Long getPodId() { + return 0L; + }; + }; + + Long newSize = 4194304L; + Long currentSize = 1048576L; + + ResizeVolumeCommand rv = new ResizeVolumeCommand("dummydiskpath", + new StorageFilerTO(dummypool), currentSize, newSize, false, + "vmName"); + + @Test + public void testExecuteInSequence() { + boolean b = rv.executeInSequence(); + assertFalse(b); + } + + @Test + public void testGetPath() { + String path = rv.getPath(); + assertTrue(path.equals("dummydiskpath")); + } + + @Test + public void testGetPoolUuid() { + String poolUuid = rv.getPoolUuid(); + assertTrue(poolUuid.equals("bed9f83e-cac3-11e1-ac8a-0050568b007e")); + } + + @Test + public void testGetPool() { + StorageFilerTO pool = rv.getPool(); + + Long id = pool.getId(); + Long expectedL = 1L; + assertEquals(expectedL, id); + + String uuid = pool.getUuid(); + assertTrue(uuid.equals("bed9f83e-cac3-11e1-ac8a-0050568b007e")); + + String host = pool.getHost(); + assertTrue(host.equals("hostAddress")); + + String path = pool.getPath(); + assertTrue(path.equals("path")); + + String userInfo = pool.getUserInfo(); + assertTrue(userInfo.equals("userInfo")); + + Integer port = pool.getPort(); + Integer expectedI = 25; + assertEquals(expectedI, port); + + StoragePoolType type = pool.getType(); + assertEquals(StoragePoolType.Filesystem, type); + + String str = pool.toString(); + assertTrue(str.equals("Pool[" + id.toString() + "|" + host + ":" + + port.toString() + "|" + path + "]")); + } + + @Test + public void testGetNewSize() { + long newSize = rv.getNewSize(); + assertTrue(newSize == 4194304L); + } + + @Test + public void testGetCurrentSize() { + long currentSize = rv.getCurrentSize(); + assertTrue(currentSize == 1048576L); + } + + @Test + public void testGetShrinkOk() { + assertFalse(rv.getShrinkOk()); + } + + @Test + public void testGetInstanceName() { + String vmName = rv.getInstanceName(); + assertTrue(vmName.equals("vmName")); + } + +} diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 99cb874a55f..182cbd8cf3b 100644 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -255,6 +255,7 @@ deleteVolume=15 listVolumes=15 extractVolume=15 migrateVolume=15 +resizeVolume=15 #### registration command: FIXME -- this really should be something in management server that #### generates a new key for the user and they just have to diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 6b5f6df3bff..b65b53114bf 100755 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -162,6 +162,8 @@ import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer; import com.cloud.agent.api.storage.DestroyCommand; import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer; import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; +import com.cloud.agent.api.storage.ResizeVolumeCommand; +import com.cloud.agent.api.storage.ResizeVolumeAnswer; import com.cloud.agent.api.to.IpAddressTO; import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.StorageFilerTO; @@ -255,6 +257,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements private String _patchdomrPath; private String _createvmPath; private String _manageSnapshotPath; + private String _resizeVolumePath; private String _createTmplPath; private String _heartBeatPath; private String _securityGroupPath; @@ -534,6 +537,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements "Unable to find the managesnapshot.sh"); } + _resizeVolumePath = Script.findScript(storageScriptsDir, "resizevolume.sh"); + if (_resizeVolumePath == null) { + throw new ConfigurationException( + "Unable to find the resizevolume.sh"); + } + _createTmplPath = Script .findScript(storageScriptsDir, "createtmplt.sh"); if (_createTmplPath == null) { @@ -1062,6 +1071,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements return execute((CleanupNetworkRulesCmd) cmd); } else if (cmd instanceof CopyVolumeCommand) { return execute((CopyVolumeCommand) cmd); + } else if (cmd instanceof ResizeVolumeCommand) { + return execute((ResizeVolumeCommand) cmd); } else if (cmd instanceof CheckNetworkCommand) { return execute((CheckNetworkCommand) cmd); } else { @@ -1268,6 +1279,72 @@ public class LibvirtComputingResource extends ServerResourceBase implements } } + private String getResizeScriptType (KVMStoragePool pool, KVMPhysicalDisk vol) { + StoragePoolType poolType = pool.getType(); + PhysicalDiskFormat volFormat = vol.getFormat(); + + if(pool.getType() == StoragePoolType.CLVM && volFormat == KVMPhysicalDisk.PhysicalDiskFormat.RAW) { + return "CLVM"; + } else if ((poolType == StoragePoolType.NetworkFilesystem + || poolType == StoragePoolType.SharedMountPoint + || poolType == StoragePoolType.Filesystem) + && volFormat == KVMPhysicalDisk.PhysicalDiskFormat.QCOW2 ) { + return "QCOW2"; + } + return null; + } + + /* uses a local script now, eventually support for virStorageVolResize() will maybe work on + qcow2 and lvm and we can do this in libvirt calls */ + public Answer execute(ResizeVolumeCommand cmd) { + String volid = cmd.getPath(); + long newSize = cmd.getNewSize(); + long currentSize = cmd.getCurrentSize(); + String vmInstanceName = cmd.getInstanceName(); + boolean shrinkOk = cmd.getShrinkOk(); + StorageFilerTO spool = cmd.getPool(); + + try { + KVMStoragePool pool = _storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid()); + KVMPhysicalDisk vol = pool.getPhysicalDisk(volid); + String path = vol.getPath(); + String type = getResizeScriptType(pool, vol); + + if (type == null) { + return new ResizeVolumeAnswer(cmd, false, "Unsupported volume format: pool type '" + + pool.getType() + "' and volume format '" + vol.getFormat() + "'"); + } + + s_logger.debug("got to the stage where we execute the volume resize, params:" + + path + "," + currentSize + "," + newSize + "," + type + "," + vmInstanceName + "," + shrinkOk); + final Script resizecmd = new Script(_resizeVolumePath, + _cmdsTimeout, s_logger); + resizecmd.add("-s",String.valueOf(newSize)); + resizecmd.add("-c",String.valueOf(currentSize)); + resizecmd.add("-p",path); + resizecmd.add("-t",type); + resizecmd.add("-r",String.valueOf(shrinkOk)); + resizecmd.add("-v",vmInstanceName); + String result = resizecmd.execute(); + + if (result == null) { + + /* fetch new size as seen from libvirt, don't want to assume anything */ + pool = _storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid()); + long finalSize = pool.getPhysicalDisk(volid).getVirtualSize(); + s_logger.debug("after resize, size reports as " + finalSize + ", requested " + newSize); + return new ResizeVolumeAnswer(cmd, true, "success", finalSize); + } + + return new ResizeVolumeAnswer(cmd, false, result); + } catch (CloudRuntimeException e) { + String error = "failed to resize volume: " + e; + s_logger.debug(error); + return new ResizeVolumeAnswer(cmd, false, error); + } + + } + public Answer execute(DestroyCommand cmd) { VolumeTO vol = cmd.getVolume(); diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 66a5918b177..065d3be0bdd 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -182,6 +182,8 @@ import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer; import com.cloud.agent.api.storage.DestroyCommand; import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer; import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; +import com.cloud.agent.api.storage.ResizeVolumeCommand; +import com.cloud.agent.api.storage.ResizeVolumeAnswer; import com.cloud.agent.api.to.IpAddressTO; import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.PortForwardingRuleTO; @@ -468,6 +470,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return execute((DeleteStoragePoolCommand) cmd); } else if (clazz == CopyVolumeCommand.class) { return execute((CopyVolumeCommand) cmd); + } else if (clazz == ResizeVolumeCommand.class) { + return execute((ResizeVolumeCommand) cmd); } else if (clazz == AttachVolumeCommand.class) { return execute((AttachVolumeCommand) cmd); } else if (clazz == AttachIsoCommand.class) { @@ -5618,6 +5622,23 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } } + public Answer execute(ResizeVolumeCommand cmd) { + Connection conn = getConnection(); + StorageFilerTO pool = cmd.getPool(); + String volid = cmd.getPath(); + long newSize = cmd.getNewSize(); + + try { + VDI vdi = getVDIbyUuid(conn, volid); + vdi.resize(conn, newSize); + return new ResizeVolumeAnswer(cmd, true, "success", newSize); + } catch (Exception e) { + s_logger.warn("Unable to resize volume",e); + String error = "failed to resize volume:" +e; + return new ResizeVolumeAnswer(cmd, false, error ); + } + } + protected SR getISOSRbyVmName(Connection conn, String vmName) { try { Set srs = SR.getByNameLabel(conn, vmName + "-ISO"); @@ -7684,4 +7705,5 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return new SetStaticRouteAnswer(cmd, false, null); } } + } diff --git a/scripts/storage/qcow2/resizevolume.sh b/scripts/storage/qcow2/resizevolume.sh new file mode 100644 index 00000000000..2de1f9ec5ca --- /dev/null +++ b/scripts/storage/qcow2/resizevolume.sh @@ -0,0 +1,253 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + + + +# resizevolume.sh -- resize a volume + +usage() { + printf "Usage: %s: -c -s -p -v -t -r \n" $(basename $0) >&2 +} + +getdevmappername() { + local path=$1 + local devmappername=`readlink -f $path |cut -d/ -f3` + if [[ $devmappername =~ "dm-" ]] + then + dmname=$devmappername + return 0 + else + return 1; + fi +} + +getdevmappersize() { + local dm=$1 + if [ ! -e "/sys/block/${dm}/size" ] + then + log "unable to find ${dm} in /sys/block" 1 + exit 1 + fi + actualsize=$((`cat /sys/block/${dm}/size`*512)); + + if [[ -z "$actualsize" ]] + then + log "unable to find actual size of ${dm}" 1 + exit 1 + fi + return 0 +} + +# log "message" 1 <-- prints to stdout as well as log, to pass error up to cloudstack +# log "message" prints only to log file +# variable shouldwelog controls whether we print to log file +log() { + local d=`date` + local msg=${1} + local stdout=${2} + + if [ ! -z "$stdout" ] + then + echo $1 + fi + + if [ $shouldwelog -eq 1 ] + then + echo "$d - $1" >> /var/log/cloud/agent/resizevolume.log + fi +} + +failshrink() { + # if this is a shrink operation, fail if commands will shrink the volume and we haven't signed of on shrinking + if [ $actualsize -gt $newsize ] + then + if [ "$shrink" == "false" ] + then + log "result would shrink the volume from $actualsize to $newsize, but confirmation to shrink wasn't passed. Shrink='$shrink'" 1 + exit 1 + fi + fi +} + +notifyqemu() { + #move this back into cloudstack libvirt calls once the libvirt java bindings support block resize + #we try to inform hypervisor of new size, but don't fail if we can't + if `virsh help 2>/dev/null | grep -q blockresize` + then + if `virsh domstate $vmname >/dev/null 2>&1` + then + sizeinkb=$(($newsize/1024)) + virsh blockresize --domain $vmname --path $path --size $sizeinkb >/dev/null 2>&1 + retval=$? + if [ -z $retval ] || [ $retval -ne 0 ] + then + log "failed to live resize $path to size of $sizeinkb kb" 1 + else + liveresize='true' + fi + fi + fi +} + +resizelvm() { + local dmname='' + local actualsize='' + local liveresize='false' + + ##### sanity checks ##### + if ! `lvresize --version > /dev/null 2>&1` + then + log "unable to resolve executable 'lvresize'" 1 + exit 1 + fi + + if ! `virsh --version > /dev/null 2>&1` + then + log "unable to resolve executable 'virsh'" 1 + exit 1 + fi + ##### end sanity ##### + + if ! getdevmappername $path + then + log "unable to resolve a device mapper dev from $path" 1 + exit 1 + fi + + getdevmappersize $dmname + + if [ $actualsize -ne $currentsize ] + then + log "disk isn't the size we think it is: cloudstack said $currentsize, disk said $actualsize." + fi + + # if this is a shrink operation, fail if commands will shrink the volume and we haven't signed of on shrinking + failshrink + + output=`lvresize -f -L ${newsize}B $path 2>&1` + retval=$? + + if [ -z $retval ] || [ $retval -ne 0 ] + then + log "lvresize failed: $output " 1 + exit 1 + fi + + #move this back into cloudstack libvirt calls once the libvirt java bindings support block resize + #we try to inform hypervisor of new size, but don't fail if we can't + notifyqemu + + log "performed successful resize - dm:$dmname currentsize:$currentsize newsize:$newsize path:$path type:$ptype vmname:$vmname live:$liveresize shrink:$shrink" +} + +resizeqcow2() { + + ##### sanity checks ##### + if [ ! -e "$path" ] + then + log "unable to find file $path" 1 + exit 1 + fi + + if ! `qemu-img info /dev/null > /dev/null 2>&1` + then + log "unable to resolve executable 'qemu-img'" 1 + exit 1 + fi + + if ! `virsh --version > /dev/null 2>&1` + then + log "unable to resolve executable 'virsh'" 1 + exit 1 + fi + ##### end sanity ##### + + $actualsize=`qemu-img info $path | grep "virtual size" | sed -re 's/^.*\(([0-9]+).*$/\1/g'` + + if [ $actualsize -ne $currentsize ] + then + log "disk isn't the size we think it is: cloudstack said $currentsize, disk said $actualsize." + fi + + # if this is a shrink operation, fail if commands will shrink the volume and we haven't signed of on shrinking + failshrink + + output=`qemu-img resize $path $newsize 2>&1` + retval=$? + + if [ -z $retval ] || [ $retval -ne 0 ] + then + log "qemu-img resize failed: $output" 1 + exit 1 + fi + + #move this back into cloudstack libvirt calls once the libvirt java bindings support block resize + #we try to inform hypervisor of new size, but don't fail if we can't + notifyqemu + + log "performed successful resize - currentsize:$currentsize newsize:$newsize path:$path type:$ptype vmname:$vmname live:$liveresize shrink:$shrink" +} + +sflag= +cflag= +pflag= +vflag= +tflag= +rflag= + +while getopts 'c:s:v:p:t:r:' OPTION +do + case $OPTION in + s) sflag=1 + newsize="$OPTARG" + ;; + c) cflag=1 + currentsize="$OPTARG" + ;; + v) vflag=1 + vmname="$OPTARG" + ;; + p) dflag=1 + path="$OPTARG" + ;; + t) tflag=1 + ptype="$OPTARG" + ;; + r) rflag=1 + shrink="$OPTARG" + ;; + ?) usage + exit 2 + ;; + esac +done + +shouldwelog=1 #set this to 1 while debugging to get output in /var/log/cloud/agent/resizevolume.log + +if [ "$ptype" == "CLVM" ] +then + resizelvm +elif [ "$ptype" == "QCOW2" ] +then + resizeqcow2 +else + echo "unsupported type $ptype" + exit 1; +fi + +exit 0 diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 96f299c02bb..55b1342bbd2 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -47,6 +47,7 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.api.command.admin.storage.*; import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd; import org.apache.cloudstack.api.command.user.volume.UploadVolumeCmd; +import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd; import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; @@ -69,6 +70,8 @@ import com.cloud.agent.api.storage.CreateCommand; import com.cloud.agent.api.storage.DeleteTemplateCommand; import com.cloud.agent.api.storage.DeleteVolumeCommand; import com.cloud.agent.api.storage.DestroyCommand; +import com.cloud.agent.api.storage.ResizeVolumeCommand; +import com.cloud.agent.api.storage.ResizeVolumeAnswer; import com.cloud.agent.api.to.StorageFilerTO; import com.cloud.agent.api.to.VolumeTO; import com.cloud.agent.manager.Commands; @@ -2098,6 +2101,183 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag } } + @Override + @DB + @ActionEvent(eventType = EventTypes.EVENT_VOLUME_RESIZE, eventDescription = "resizing volume", async = true) + public VolumeVO resizeVolume(ResizeVolumeCmd cmd) { + VolumeVO volume = _volsDao.findById(cmd.getEntityId()); + Long newSize = null; + boolean shrinkOk = cmd.getShrinkOk(); + boolean success = false; + DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId()); + DiskOfferingVO newDiskOffering = null; + + newDiskOffering = _diskOfferingDao.findById(cmd.getNewDiskOfferingId()); + + /* Volumes with no hypervisor have never been assigned, and can be resized by recreating. + perhaps in the future we can just update the db entry for the volume */ + if(_volsDao.getHypervisorType(volume.getId()) == HypervisorType.None){ + throw new InvalidParameterValueException("Can't resize a volume that has never been attached, not sure which hypervisor type. Recreate volume to resize."); + } + + /* Only works for KVM/Xen for now */ + if(_volsDao.getHypervisorType(volume.getId()) != HypervisorType.KVM + && _volsDao.getHypervisorType(volume.getId()) != HypervisorType.XenServer){ + throw new InvalidParameterValueException("Cloudstack currently only supports volumes marked as KVM or XenServer hypervisor for resize"); + } + + if (volume == null) { + throw new InvalidParameterValueException("No such volume"); + } + + if (volume.getState() != Volume.State.Ready) { + throw new InvalidParameterValueException("Volume should be in ready state before attempting a resize"); + } + + if (!volume.getVolumeType().equals(Volume.Type.DATADISK)) { + throw new InvalidParameterValueException("Can only resize DATA volumes"); + } + + /* figure out whether or not a new disk offering or size parameter is required, get the correct size value */ + if (newDiskOffering == null) { + if (diskOffering.isCustomized()) { + newSize = cmd.getSize(); + + if (newSize == null) { + throw new InvalidParameterValueException("new offering is of custom size, need to specify a size"); + } + + newSize = ( newSize << 30 ); + } else { + throw new InvalidParameterValueException("current offering" + volume.getDiskOfferingId() + " cannot be resized, need to specify a disk offering"); + } + } else { + + if (newDiskOffering.getRemoved() != null || !DiskOfferingVO.Type.Disk.equals(newDiskOffering.getType())) { + throw new InvalidParameterValueException("Disk offering ID is missing or invalid"); + } + + if(diskOffering.getTags() != null) { + if(!newDiskOffering.getTags().equals(diskOffering.getTags())){ + throw new InvalidParameterValueException("Tags on new and old disk offerings must match"); + } + } else if (newDiskOffering.getTags() != null ){ + throw new InvalidParameterValueException("There are no tags on current disk offering, new disk offering needs to have no tags"); + } + + if (newDiskOffering.getDomainId() == null) { + // do nothing as offering is public + } else { + _configMgr.checkDiskOfferingAccess(UserContext.current().getCaller(), newDiskOffering); + } + + if (newDiskOffering.isCustomized()) { + newSize = cmd.getSize(); + + if (newSize == null) { + throw new InvalidParameterValueException("new offering is of custom size, need to specify a size"); + } + + newSize = ( newSize << 30 ); + } else { + newSize = newDiskOffering.getDiskSize(); + } + } + + if (newSize == null) { + throw new InvalidParameterValueException("could not detect a size parameter or fetch one from the diskofferingid parameter"); + } + + if (!validateVolumeSizeRange(newSize)) { + throw new InvalidParameterValueException("Requested size out of range"); + } + + /* does the caller have the authority to act on this volume? */ + _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, volume); + + UserVmVO userVm = _userVmDao.findById(volume.getInstanceId()); + + StoragePool pool = _storagePoolDao.findById(volume.getPoolId()); + long currentSize = volume.getSize(); + + /* lets make certain they (think they) know what they're doing if they + want to shrink, by forcing them to provide the shrinkok parameter. This will + be checked again at the hypervisor level where we can see the actual disk size */ + if (currentSize > newSize && !shrinkOk) { + throw new InvalidParameterValueException("Going from existing size of " + currentSize + " to size of " + + newSize + " would shrink the volume, need to sign off by supplying the shrinkok parameter with value of true"); + } + + /* get a list of hosts to send the commands to, try the system the + associated vm is running on first, then the last known place it ran. + If not attached to a userVm, we pass 'none' and resizevolume.sh is + ok with that since it only needs the vm name to live resize */ + long[] hosts = null; + String instanceName = "none"; + if (userVm != null) { + instanceName = userVm.getInstanceName(); + if(userVm.getHostId() != null) { + hosts = new long[] { userVm.getHostId() }; + } else if(userVm.getLastHostId() != null) { + hosts = new long[] { userVm.getLastHostId() }; + } + + /*Xen only works offline, SR does not support VDI.resizeOnline*/ + if(_volsDao.getHypervisorType(volume.getId()) == HypervisorType.XenServer + && ! userVm.getState().equals(State.Stopped)) { + throw new InvalidParameterValueException("VM must be stopped or disk detached in order to resize with the Xen HV"); + } + } + + try { + try { + stateTransitTo(volume, Volume.Event.ResizeRequested); + } catch (NoTransitionException etrans) { + throw new CloudRuntimeException("Unable to change volume state for resize: " + etrans.toString()); + } + + ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(volume.getPath(), new StorageFilerTO(pool), + currentSize, newSize, shrinkOk, instanceName); + ResizeVolumeAnswer answer = (ResizeVolumeAnswer) sendToPool(pool, hosts, resizeCmd); + + /* need to fetch/store new volume size in database. This value comes from + hypervisor rather than trusting that a success means we have a volume of the + size we requested */ + if (answer != null && answer.getResult()) { + long finalSize = answer.getNewSize(); + s_logger.debug("Resize: volume started at size " + currentSize + " and ended at size " + finalSize); + volume.setSize(finalSize); + if (newDiskOffering != null) { + volume.setDiskOfferingId(cmd.getNewDiskOfferingId()); + } + _volsDao.update(volume.getId(), volume); + + success = true; + return volume; + } else if (answer != null) { + s_logger.debug("Resize: returned '" + answer.getDetails() + "'"); + } + } catch (StorageUnavailableException e) { + s_logger.debug("volume failed to resize: "+e); + return null; + } finally { + if(success) { + try { + stateTransitTo(volume, Volume.Event.OperationSucceeded); + } catch (NoTransitionException etrans) { + throw new CloudRuntimeException("Failed to change volume state: " + etrans.toString()); + } + } else { + try { + stateTransitTo(volume, Volume.Event.OperationFailed); + } catch (NoTransitionException etrans) { + throw new CloudRuntimeException("Failed to change volume state: " + etrans.toString()); + } + } + } + return null; + } + @Override @DB public boolean destroyVolume(VolumeVO volume) throws ConcurrentOperationException { diff --git a/setup/db/create-schema-view.sql b/setup/db/create-schema-view.sql old mode 100755 new mode 100644 diff --git a/test/integration/smoke/test_volumes.py b/test/integration/smoke/test_volumes.py index 3fe68ec5621..36eb5ded263 100644 --- a/test/integration/smoke/test_volumes.py +++ b/test/integration/smoke/test_volumes.py @@ -54,12 +54,20 @@ class Services: "cpunumber": 1, "cpuspeed": 100, # in MHz "memory": 128, # In MBs + "storagetype": "local" }, "disk_offering": { "displaytext": "Small", "name": "Small", + "storagetype": "local", "disksize": 1 }, + 'resized_disk_offering': { + "displaytext": "Resized", + "name": "Resized", + "storagetype": "local", + "disksize": 3 + }, "volume_offerings": { 0: { "diskname": "TestDiskServ", @@ -77,8 +85,8 @@ class Services: "diskdevice": "/dev/xvdb", "ostype": 'CentOS 5.3 (64-bit)', "mode": 'basic', - "sleep": 60, - "timeout": 10, + "sleep": 10, + "timeout": 600, } @@ -237,7 +245,7 @@ class TestCreateVolume(cloudstackTestCase): ssh = self.virtual_machine.get_ssh_client( reconnect=True ) - c = "fdisk -l" + c = "/sbin/fdisk -l" res = ssh.execute(c) except Exception as e: @@ -283,6 +291,16 @@ class TestVolumes(cloudstackTestCase): cls.api_client, cls.services["disk_offering"] ) + cls.resized_disk_offering = DiskOffering.create( + cls.api_client, + cls.services["resized_disk_offering"] + ) + cls.custom_resized_disk_offering = DiskOffering.create( + cls.api_client, + cls.services["resized_disk_offering"], + custom=True + ) + template = get_template( cls.api_client, cls.zone.id, @@ -292,6 +310,8 @@ class TestVolumes(cloudstackTestCase): cls.services["zoneid"] = cls.zone.id cls.services["template"] = template.id cls.services["diskofferingid"] = cls.disk_offering.id + cls.services['resizeddiskofferingid'] = cls.resized_disk_offering.id + cls.services['customresizeddiskofferingid'] = cls.custom_resized_disk_offering.id # Create VMs, VMs etc cls.account = Account.create( @@ -321,6 +341,8 @@ class TestVolumes(cloudstackTestCase): domainid=cls.account.account.domainid ) cls._cleanup = [ + cls.resized_disk_offering, + cls.custom_resized_disk_offering, cls.service_offering, cls.disk_offering, cls.account @@ -500,7 +522,102 @@ class TestVolumes(cloudstackTestCase): ) @attr(tags = ["advanced", "advancedns", "smoke"]) - def test_07_delete_detached_volume(self): + def test_07_resize_fail(self): + """Verify invalid options fail to Resize a volume""" + # Verify the size is the new size is what we wanted it to be. + self.debug("Fail Resize Volume ID: %s" % self.volume.id) + + # first, an invalid id + cmd = resizeVolume.resizeVolumeCmd() + cmd.id = "invalid id" + cmd.diskofferingid = self.services['resizeddiskofferingid'] + success = False + try: + response = self.apiClient.resizeVolume(cmd) + except Exception as ex: + if str(ex) == "HTTP Error 431: 431": + success = True + self.assertEqual(success, True, "ResizeVolume - verify invalid id is handled appropriately") + + # Next, we'll try an invalid disk offering id + cmd.id = self.volume.id + cmd.diskofferingid = "invalid id" + success = False + try: + response = self.apiClient.resizeVolume(cmd) + except Exception as ex: + if "need to specify a disk offering" in str(ex): + success = True + self.assertEqual(success, True, "ResizeVolume - verify disk offering is handled appropriately") + + # Ok, now let's try and resize a volume that is not custom. + cmd.id = self.volume.id + cmd.diskofferingid = self.services['diskofferingid'] + cmd.size = 4 + currentSize = self.volume.size + + self.apiClient.resizeVolume(cmd) + count = 0 + success = True + while count < 10: + list_volume_response = list_volumes( + self.apiClient, + id=self.volume.id, + type='DATADISK' + ) + for vol in list_volume_response: + if vol.id == self.volume.id and vol.size != currentSize: + success = False + if success: + break + else: + time.sleep(1) + count += 1 + + self.assertEqual( + success, + True, + "Verify the volume did not resize" + ) + + + @attr(tags = ["advanced", "advancedns", "smoke"]) + def test_08_resize_volume(self): + """Resize a volume""" + # Verify the size is the new size is what we wanted it to be. + self.debug("Resize Volume ID: %s" % self.volume.id) + + cmd = resizeVolume.resizeVolumeCmd() + cmd.id = self.volume.id + cmd.diskofferingid = self.services['resizeddiskofferingid'] + + self.apiClient.resizeVolume(cmd) + + count = 0 + success = False + while count < 3: + list_volume_response = list_volumes( + self.apiClient, + id=self.volume.id, + type='DATADISK' + ) + for vol in list_volume_response: + if vol.id == self.volume.id and vol.size == 3221225472L: + success = True + if success: + break + else: + time.sleep(10) + count += 1 + + self.assertEqual( + success, + True, + "Check if the volume resized appropriately" + ) + + @attr(tags = ["advanced", "advancedns", "smoke"]) + def test_09_delete_detached_volume(self): """Delete a Volume unattached to an VM """ # Validate the following diff --git a/tools/marvin/marvin/integration/lib/base.py b/tools/marvin/marvin/integration/lib/base.py index 726a628d070..87b0bbb7bbc 100644 --- a/tools/marvin/marvin/integration/lib/base.py +++ b/tools/marvin/marvin/integration/lib/base.py @@ -509,6 +509,12 @@ class Volume: [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listVolumes(cmd)) + def resize(cls, apiclient, **kwargs): + """Resize a volume""" + cmd = resizeVolume.resizeVolumeCmd() + cmd.id = self.id + [setattr(cmd, k, v) for k, v in kwargs.items()] + return(apiclient.resizeVolume(cmd)) class Snapshot: """Manage Snapshot Lifecycle From c08d151e0572ce105b71658ea40978b66c5c0f69 Mon Sep 17 00:00:00 2001 From: Prachi Damle Date: Wed, 16 Jan 2013 17:16:48 -0800 Subject: [PATCH 4/5] https://issues.apache.org/jira/browse/CLOUDSTACK-993 Changes: - Introduction of maven skipped the java code that inserts the admin user. This causes the NPE in management server while trying to find the user and also, admin user cannot login as expected. - Fixing the insertion of the admin user as part of startup. --- server/src/com/cloud/server/ConfigurationServerImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 5d246281630..74fba896753 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -341,8 +341,8 @@ public class ConfigurationServerImpl implements ConfigurationServer { } // now insert the user - insertSql = "INSERT INTO `cloud`.`user` (id, uuid, username, account_id, firstname, lastname, created, state) " + - "VALUES (" + id + ", UUID(), '" + username + "', 2, '" + firstname + "','" + lastname + "',now(), 'disabled')"; + insertSql = "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, created, state) " + + "VALUES (" + id + ",'" + username + "', RAND(), 2, '" + firstname + "','" + lastname + "',now(), 'disabled')"; txn = Transaction.currentTxn(); try { From 3dabd5fbf3b0ddfcbe98e4a6178e206b1de2c7f7 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Wed, 16 Jan 2013 21:52:48 -0800 Subject: [PATCH 5/5] Clean up ApiServer, ApiServlet and ApiDispatcher flow to handle various CloudRuntimeException and CloudException in one place, and Introduced ApiErrorCode to handle CloudStack API error code to standard Http code mapping. Signed-off-by: Min Chen --- .../api/commands/CreatePrivateNetworkCmd.java | 8 +- .../api/commands/DestroyConsoleProxyCmd.java | 2 +- .../apache/cloudstack/api/ApiErrorCode.java | 59 +++++ .../org/apache/cloudstack/api/BaseCmd.java | 25 +- ...BaseUpdateTemplateOrIsoPermissionsCmd.java | 2 +- .../cloudstack/api/ServerApiException.java | 33 ++- .../admin/account/CreateAccountCmd.java | 2 +- .../admin/account/DeleteAccountCmd.java | 2 +- .../admin/account/DisableAccountCmd.java | 2 +- .../admin/account/EnableAccountCmd.java | 3 +- .../command/admin/account/LockAccountCmd.java | 2 +- .../admin/account/UpdateAccountCmd.java | 3 +- .../admin/autoscale/CreateCounterCmd.java | 3 +- .../admin/autoscale/DeleteCounterCmd.java | 5 +- .../command/admin/cluster/AddClusterCmd.java | 6 +- .../admin/cluster/DeleteClusterCmd.java | 3 +- .../admin/cluster/UpdateClusterCmd.java | 3 +- .../command/admin/config/UpdateCfgCmd.java | 3 +- .../UpdateHypervisorCapabilitiesCmd.java | 3 +- .../command/admin/domain/CreateDomainCmd.java | 2 +- .../command/admin/domain/DeleteDomainCmd.java | 2 +- .../command/admin/domain/UpdateDomainCmd.java | 2 +- .../api/command/admin/host/AddHostCmd.java | 5 +- .../admin/host/AddSecondaryStorageCmd.java | 4 +- .../admin/host/CancelMaintenanceCmd.java | 3 +- .../api/command/admin/host/DeleteHostCmd.java | 3 +- .../admin/host/PrepareForMaintenanceCmd.java | 3 +- .../command/admin/host/ReconnectHostCmd.java | 5 +- .../api/command/admin/host/UpdateHostCmd.java | 3 +- .../admin/network/AddNetworkDeviceCmd.java | 5 +- .../network/AddNetworkServiceProviderCmd.java | 5 +- .../network/CreateNetworkOfferingCmd.java | 2 +- .../network/CreatePhysicalNetworkCmd.java | 5 +- .../CreateStorageNetworkIpRangeCmd.java | 3 +- .../admin/network/DeleteNetworkDeviceCmd.java | 7 +- .../network/DeleteNetworkOfferingCmd.java | 3 +- .../DeleteNetworkServiceProviderCmd.java | 7 +- .../network/DeletePhysicalNetworkCmd.java | 2 +- .../DeleteStorageNetworkIpRangeCmd.java | 2 +- .../admin/network/ListNetworkDeviceCmd.java | 5 +- .../network/ListPhysicalNetworksCmd.java | 3 +- .../network/ListStorageNetworkIpRangeCmd.java | 2 +- .../network/UpdateNetworkOfferingCmd.java | 2 +- .../UpdateNetworkServiceProviderCmd.java | 3 +- .../UpdateStorageNetworkIpRangeCmd.java | 2 +- .../admin/offering/CreateDiskOfferingCmd.java | 3 +- .../offering/CreateServiceOfferingCmd.java | 3 +- .../admin/offering/DeleteDiskOfferingCmd.java | 3 +- .../offering/DeleteServiceOfferingCmd.java | 2 +- .../admin/offering/UpdateDiskOfferingCmd.java | 3 +- .../offering/UpdateServiceOfferingCmd.java | 2 +- .../api/command/admin/pod/CreatePodCmd.java | 2 +- .../api/command/admin/pod/DeletePodCmd.java | 3 +- .../api/command/admin/pod/UpdatePodCmd.java | 2 +- .../resource/UploadCustomCertificateCmd.java | 2 +- .../ConfigureVirtualRouterElementCmd.java | 3 +- .../router/CreateVirtualRouterElementCmd.java | 4 +- .../admin/router/DestroyRouterCmd.java | 3 +- .../command/admin/router/RebootRouterCmd.java | 2 +- .../command/admin/router/StartRouterCmd.java | 2 +- .../command/admin/router/StopRouterCmd.java | 3 +- .../admin/router/UpgradeRouterCmd.java | 2 +- .../api/command/admin/storage/AddS3Cmd.java | 5 +- .../CancelPrimaryStorageMaintenanceCmd.java | 3 +- .../admin/storage/CreateStoragePoolCmd.java | 8 +- .../command/admin/storage/DeletePoolCmd.java | 4 +- ...reparePrimaryStorageForMaintenanceCmd.java | 3 +- .../admin/storage/UpdateStoragePoolCmd.java | 2 +- .../api/command/admin/swift/AddSwiftCmd.java | 4 +- .../admin/systemvm/DestroySystemVmCmd.java | 2 +- .../admin/systemvm/MigrateSystemVMCmd.java | 11 +- .../admin/systemvm/RebootSystemVmCmd.java | 3 +- .../admin/systemvm/StartSystemVMCmd.java | 3 +- .../admin/systemvm/StopSystemVmCmd.java | 2 +- .../admin/systemvm/UpgradeSystemVMCmd.java | 2 +- .../admin/usage/AddTrafficTypeCmd.java | 5 +- .../admin/usage/DeleteTrafficTypeCmd.java | 3 +- .../admin/usage/UpdateTrafficTypeCmd.java | 3 +- .../api/command/admin/user/CreateUserCmd.java | 3 +- .../api/command/admin/user/DeleteUserCmd.java | 3 +- .../command/admin/user/DisableUserCmd.java | 3 +- .../api/command/admin/user/EnableUserCmd.java | 2 +- .../api/command/admin/user/LockUserCmd.java | 3 +- .../api/command/admin/user/UpdateUserCmd.java | 2 +- .../admin/vlan/CreateVlanIpRangeCmd.java | 6 +- .../admin/vlan/DeleteVlanIpRangeCmd.java | 3 +- .../api/command/admin/vm/AssignVMCmd.java | 4 +- .../api/command/admin/vm/MigrateVMCmd.java | 10 +- .../api/command/admin/vm/RecoverVMCmd.java | 3 +- .../admin/vpc/CreatePrivateGatewayCmd.java | 9 +- .../admin/vpc/CreateVPCOfferingCmd.java | 4 +- .../admin/vpc/DeletePrivateGatewayCmd.java | 3 +- .../admin/vpc/DeleteVPCOfferingCmd.java | 3 +- .../admin/vpc/UpdateVPCOfferingCmd.java | 2 +- .../api/command/admin/zone/CreateZoneCmd.java | 3 +- .../api/command/admin/zone/DeleteZoneCmd.java | 2 +- .../zone/MarkDefaultZoneForAccountCmd.java | 3 +- .../api/command/admin/zone/UpdateZoneCmd.java | 2 +- .../user/account/AddAccountToProjectCmd.java | 2 +- .../account/DeleteAccountFromProjectCmd.java | 2 +- .../user/address/AssociateIPAddrCmd.java | 9 +- .../user/address/DisassociateIPAddrCmd.java | 2 +- .../autoscale/CreateAutoScalePolicyCmd.java | 2 +- .../autoscale/CreateAutoScaleVmGroupCmd.java | 4 +- .../CreateAutoScaleVmProfileCmd.java | 3 +- .../user/autoscale/CreateConditionCmd.java | 3 +- .../autoscale/DeleteAutoScalePolicyCmd.java | 3 +- .../autoscale/DeleteAutoScaleVmGroupCmd.java | 3 +- .../DeleteAutoScaleVmProfileCmd.java | 3 +- .../user/autoscale/DeleteConditionCmd.java | 5 +- .../autoscale/DisableAutoScaleVmGroupCmd.java | 3 +- .../autoscale/EnableAutoScaleVmGroupCmd.java | 2 +- .../autoscale/UpdateAutoScalePolicyCmd.java | 3 +- .../autoscale/UpdateAutoScaleVmGroupCmd.java | 2 +- .../UpdateAutoScaleVmProfileCmd.java | 2 +- .../user/firewall/CreateFirewallRuleCmd.java | 7 +- .../firewall/CreatePortForwardingRuleCmd.java | 4 +- .../user/firewall/DeleteFirewallRuleCmd.java | 2 +- .../firewall/DeletePortForwardingRuleCmd.java | 2 +- .../firewall/UpdatePortForwardingRuleCmd.java | 2 +- .../api/command/user/iso/AttachIsoCmd.java | 5 +- .../api/command/user/iso/DeleteIsoCmd.java | 3 +- .../api/command/user/iso/DetachIsoCmd.java | 3 +- .../api/command/user/iso/ExtractIsoCmd.java | 4 +- .../api/command/user/iso/RegisterIsoCmd.java | 2 +- .../api/command/user/iso/UpdateIsoCmd.java | 3 +- .../AssignToLoadBalancerRuleCmd.java | 3 +- .../CreateLBStickinessPolicyCmd.java | 5 +- .../CreateLoadBalancerRuleCmd.java | 7 +- .../DeleteLBStickinessPolicyCmd.java | 3 +- .../DeleteLoadBalancerRuleCmd.java | 2 +- .../RemoveFromLoadBalancerRuleCmd.java | 2 +- .../UpdateLoadBalancerRuleCmd.java | 2 +- .../user/nat/CreateIpForwardingRuleCmd.java | 5 +- .../user/nat/DeleteIpForwardingRuleCmd.java | 3 +- .../command/user/nat/DisableStaticNatCmd.java | 3 +- .../command/user/nat/EnableStaticNatCmd.java | 5 +- .../user/network/CreateNetworkACLCmd.java | 7 +- .../user/network/CreateNetworkCmd.java | 3 +- .../user/network/DeleteNetworkACLCmd.java | 3 +- .../user/network/DeleteNetworkCmd.java | 2 +- .../user/network/RestartNetworkCmd.java | 2 +- .../user/network/UpdateNetworkCmd.java | 3 +- .../user/project/ActivateProjectCmd.java | 2 +- .../user/project/CreateProjectCmd.java | 4 +- .../user/project/DeleteProjectCmd.java | 3 +- .../project/DeleteProjectInvitationCmd.java | 3 +- .../user/project/SuspendProjectCmd.java | 2 +- .../user/project/UpdateProjectCmd.java | 3 +- .../project/UpdateProjectInvitationCmd.java | 2 +- .../user/resource/GetCloudIdentifierCmd.java | 3 +- .../user/resource/UpdateResourceCountCmd.java | 2 +- .../user/resource/UpdateResourceLimitCmd.java | 2 +- .../AuthorizeSecurityGroupEgressCmd.java | 2 +- .../AuthorizeSecurityGroupIngressCmd.java | 5 +- .../securitygroup/CreateSecurityGroupCmd.java | 3 +- .../securitygroup/DeleteSecurityGroupCmd.java | 5 +- .../RevokeSecurityGroupEgressCmd.java | 2 +- .../RevokeSecurityGroupIngressCmd.java | 3 +- .../user/snapshot/CreateSnapshotCmd.java | 4 +- .../snapshot/CreateSnapshotPolicyCmd.java | 2 +- .../user/snapshot/DeleteSnapshotCmd.java | 2 +- .../snapshot/DeleteSnapshotPoliciesCmd.java | 3 +- .../api/command/user/tag/CreateTagsCmd.java | 3 +- .../api/command/user/tag/DeleteTagsCmd.java | 3 +- .../user/template/CopyTemplateCmd.java | 5 +- .../user/template/CreateTemplateCmd.java | 4 +- .../user/template/DeleteTemplateCmd.java | 2 +- .../user/template/ExtractTemplateCmd.java | 4 +- .../user/template/RegisterTemplateCmd.java | 5 +- .../user/template/UpdateTemplateCmd.java | 3 +- .../api/command/user/vm/DeployVMCmd.java | 16 +- .../api/command/user/vm/DestroyVMCmd.java | 2 +- .../api/command/user/vm/RebootVMCmd.java | 3 +- .../command/user/vm/ResetVMPasswordCmd.java | 3 +- .../api/command/user/vm/RestoreVMCmd.java | 3 +- .../api/command/user/vm/StartVMCmd.java | 8 +- .../api/command/user/vm/StopVMCmd.java | 2 +- .../api/command/user/vm/UpdateVMCmd.java | 3 +- .../api/command/user/vm/UpgradeVMCmd.java | 2 +- .../user/vmgroup/CreateVMGroupCmd.java | 2 +- .../user/vmgroup/DeleteVMGroupCmd.java | 2 +- .../user/vmgroup/UpdateVMGroupCmd.java | 2 +- .../command/user/volume/AttachVolumeCmd.java | 3 +- .../command/user/volume/CreateVolumeCmd.java | 5 +- .../command/user/volume/DeleteVolumeCmd.java | 3 +- .../command/user/volume/DetachVolumeCmd.java | 2 +- .../command/user/volume/ExtractVolumeCmd.java | 5 +- .../command/user/volume/MigrateVolumeCmd.java | 3 +- .../command/user/volume/ResizeVolumeCmd.java | 13 +- .../command/user/volume/UploadVolumeCmd.java | 2 +- .../user/vpc/CreateStaticRouteCmd.java | 5 +- .../api/command/user/vpc/CreateVPCCmd.java | 11 +- .../user/vpc/DeleteStaticRouteCmd.java | 2 +- .../api/command/user/vpc/DeleteVPCCmd.java | 6 +- .../api/command/user/vpc/RestartVPCCmd.java | 8 +- .../api/command/user/vpc/UpdateVPCCmd.java | 3 +- .../api/command/user/vpn/AddVpnUserCmd.java | 5 +- .../user/vpn/CreateRemoteAccessVpnCmd.java | 8 +- .../user/vpn/CreateVpnConnectionCmd.java | 8 +- .../user/vpn/CreateVpnCustomerGatewayCmd.java | 3 +- .../command/user/vpn/CreateVpnGatewayCmd.java | 3 +- .../user/vpn/DeleteVpnConnectionCmd.java | 4 +- .../user/vpn/DeleteVpnCustomerGatewayCmd.java | 2 +- .../command/user/vpn/DeleteVpnGatewayCmd.java | 2 +- .../command/user/vpn/RemoveVpnUserCmd.java | 5 +- .../user/vpn/ResetVpnConnectionCmd.java | 4 +- .../user/vpn/UpdateVpnCustomerGatewayCmd.java | 2 +- .../command/user/discovery/ListApisCmd.java | 3 +- .../api/commands/netapp/AssociateLunCmd.java | 27 +- .../api/commands/netapp/CreateLunCmd.java | 21 +- .../netapp/CreateVolumeOnFilerCmd.java | 49 ++-- .../commands/netapp/CreateVolumePoolCmd.java | 13 +- .../commands/netapp/DeleteVolumePoolCmd.java | 9 +- .../api/commands/netapp/DestroyLunCmd.java | 9 +- .../netapp/DestroyVolumeOnFilerCmd.java | 20 +- .../api/commands/netapp/DissociateLunCmd.java | 8 +- .../api/commands/netapp/ListLunsCmd.java | 7 +- .../commands/netapp/ListVolumePoolsCmd.java | 7 +- .../netapp/ListVolumesOnFilerCmd.java | 8 +- .../api/commands/ConfigureSimulator.java | 3 +- .../api/commands/DeleteCiscoNexusVSMCmd.java | 5 +- .../api/commands/DisableCiscoNexusVSMCmd.java | 5 +- .../api/commands/EnableCiscoNexusVSMCmd.java | 2 +- .../api/commands/ListCiscoNexusVSMsCmd.java | 15 +- .../commands/AddExternalLoadBalancerCmd.java | 17 +- .../api/commands/AddF5LoadBalancerCmd.java | 10 +- .../commands/ConfigureF5LoadBalancerCmd.java | 6 +- .../DeleteExternalLoadBalancerCmd.java | 16 +- .../api/commands/DeleteF5LoadBalancerCmd.java | 7 +- .../ListF5LoadBalancerNetworksCmd.java | 5 +- .../api/commands/ListF5LoadBalancersCmd.java | 4 +- .../api/commands/AddExternalFirewallCmd.java | 37 +-- .../cloud/api/commands/AddSrxFirewallCmd.java | 13 +- .../api/commands/ConfigureSrxFirewallCmd.java | 9 +- .../commands/DeleteExternalFirewallCmd.java | 21 +- .../api/commands/DeleteSrxFirewallCmd.java | 9 +- .../commands/ListSrxFirewallNetworksCmd.java | 6 +- .../api/commands/ListSrxFirewallsCmd.java | 6 +- .../commands/AddNetscalerLoadBalancerCmd.java | 10 +- .../ConfigureNetscalerLoadBalancerCmd.java | 6 +- .../DeleteNetscalerLoadBalancerCmd.java | 7 +- .../ListNetscalerLoadBalancerNetworksCmd.java | 5 +- .../ListNetscalerLoadBalancersCmd.java | 5 +- .../api/commands/AddNiciraNvpDeviceCmd.java | 22 +- .../commands/DeleteNiciraNvpDeviceCmd.java | 7 +- .../ListNiciraNvpDeviceNetworksCmd.java | 5 +- .../api/commands/ListNiciraNvpDevicesCmd.java | 7 +- server/src/com/cloud/api/ApiDispatcher.java | 233 +++-------------- server/src/com/cloud/api/ApiServer.java | 234 +++++++++++------- server/src/com/cloud/api/ApiServlet.java | 58 ++--- .../api/commands/AddTrafficMonitorCmd.java | 4 +- .../api/commands/DeleteTrafficMonitorCmd.java | 23 +- .../api/commands/GenerateUsageRecordsCmd.java | 2 +- .../com/cloud/async/AsyncJobManagerImpl.java | 158 ++++++------ .../utils/exception/CSExceptionErrorCode.java | 32 --- 256 files changed, 1040 insertions(+), 995 deletions(-) create mode 100644 api/src/org/apache/cloudstack/api/ApiErrorCode.java diff --git a/api/src/com/cloud/api/commands/CreatePrivateNetworkCmd.java b/api/src/com/cloud/api/commands/CreatePrivateNetworkCmd.java index 263f023b3e5..1cc20d78930 100644 --- a/api/src/com/cloud/api/commands/CreatePrivateNetworkCmd.java +++ b/api/src/com/cloud/api/commands/CreatePrivateNetworkCmd.java @@ -145,17 +145,17 @@ public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd { } catch (InsufficientCapacityException ex){ s_logger.info(ex); s_logger.trace(ex); - throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } if (result != null) { this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a Private network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a Private network"); } } @@ -167,7 +167,7 @@ public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private network"); } } diff --git a/api/src/com/cloud/api/commands/DestroyConsoleProxyCmd.java b/api/src/com/cloud/api/commands/DestroyConsoleProxyCmd.java index 80269075744..e749f2210ce 100644 --- a/api/src/com/cloud/api/commands/DestroyConsoleProxyCmd.java +++ b/api/src/com/cloud/api/commands/DestroyConsoleProxyCmd.java @@ -84,7 +84,7 @@ public class DestroyConsoleProxyCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to destroy console proxy"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to destroy console proxy"); } } } diff --git a/api/src/org/apache/cloudstack/api/ApiErrorCode.java b/api/src/org/apache/cloudstack/api/ApiErrorCode.java new file mode 100644 index 00000000000..51671cd7ec2 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/ApiErrorCode.java @@ -0,0 +1,59 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api; + +/** + * Enum class for various API error code used in CloudStack + * @author minc + * + */ +public enum ApiErrorCode { + + MALFORMED_PARAMETER_ERROR(430), + PARAM_ERROR(431), + UNSUPPORTED_ACTION_ERROR(432), + API_LIMIT_EXCEED(429), + + INTERNAL_ERROR(530), + ACCOUNT_ERROR(531), + ACCOUNT_RESOURCE_LIMIT_ERROR(532), + INSUFFICIENT_CAPACITY_ERROR(533), + RESOURCE_UNAVAILABLE_ERROR(534), + RESOURCE_ALLOCATION_ERROR(534), + RESOURCE_IN_USE_ERROR(536), + NETWORK_RULE_CONFLICT_ERROR(537); + + private int httpCode; + + private ApiErrorCode(int httpStatusCode){ + httpCode = httpStatusCode; + } + + public int getHttpCode() { + return httpCode; + } + + public void setHttpCode(int httpCode) { + this.httpCode = httpCode; + } + + public String toString(){ + return String.valueOf(this.httpCode); + } + + +} diff --git a/api/src/org/apache/cloudstack/api/BaseCmd.java b/api/src/org/apache/cloudstack/api/BaseCmd.java index 3399784d2a2..ef72af9cae9 100644 --- a/api/src/org/apache/cloudstack/api/BaseCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseCmd.java @@ -81,23 +81,6 @@ public abstract class BaseCmd { BOOLEAN, DATE, FLOAT, INTEGER, SHORT, LIST, LONG, OBJECT, MAP, STRING, TZDATE, UUID } - // FIXME: Extract these out into a separate file - // Client error codes - public static final int MALFORMED_PARAMETER_ERROR = 430; - public static final int PARAM_ERROR = 431; - public static final int UNSUPPORTED_ACTION_ERROR = 432; - public static final int PAGE_LIMIT_EXCEED = 433; - - // Server error codes - public static final int INTERNAL_ERROR = 530; - public static final int ACCOUNT_ERROR = 531; - public static final int ACCOUNT_RESOURCE_LIMIT_ERROR = 532; - public static final int INSUFFICIENT_CAPACITY_ERROR = 533; - public static final int RESOURCE_UNAVAILABLE_ERROR = 534; - public static final int RESOURCE_ALLOCATION_ERROR = 534; - public static final int RESOURCE_IN_USE_ERROR = 536; - public static final int NETWORK_RULE_CONFLICT_ERROR = 537; - public static final DateFormat INPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); public static final DateFormat NEW_INPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static Pattern newInputDateFormat = Pattern.compile("[\\d]+-[\\d]+-[\\d]+ [\\d]+:[\\d]+:[\\d]+"); @@ -230,7 +213,7 @@ public abstract class BaseCmd { int arrayStartIndex = key.indexOf('['); int arrayStartLastIndex = key.lastIndexOf('['); if (arrayStartIndex != arrayStartLastIndex) { - throw new ServerApiException(MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key + throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key + "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup"); } @@ -239,7 +222,7 @@ public abstract class BaseCmd { int arrayEndLastIndex = key.lastIndexOf(']'); if ((arrayEndIndex < arrayStartIndex) || (arrayEndIndex != arrayEndLastIndex)) { // malformed parameter - throw new ServerApiException(MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key + throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key + "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup"); } @@ -247,7 +230,7 @@ public abstract class BaseCmd { int fieldIndex = key.indexOf('.'); String fieldName = null; if (fieldIndex < arrayEndIndex) { - throw new ServerApiException(MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key + throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key + "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup"); } else { fieldName = key.substring(fieldIndex + 1); @@ -272,7 +255,7 @@ public abstract class BaseCmd { } if (!parsedIndex) { - throw new ServerApiException(MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key + throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "Unable to decode parameter " + key + "; if specifying an object array, please use parameter[index].field=XXX, e.g. userGroupList[0].group=httpGroup"); } diff --git a/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java b/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java index aacc6efa2e0..3222c710c5d 100644 --- a/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java @@ -119,7 +119,7 @@ public abstract class BaseUpdateTemplateOrIsoPermissionsCmd extends BaseCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update template/iso permissions"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update template/iso permissions"); } } } diff --git a/api/src/org/apache/cloudstack/api/ServerApiException.java b/api/src/org/apache/cloudstack/api/ServerApiException.java index 1f57b74745d..682e5b7e774 100644 --- a/api/src/org/apache/cloudstack/api/ServerApiException.java +++ b/api/src/org/apache/cloudstack/api/ServerApiException.java @@ -15,28 +15,51 @@ // specific language governing permissions and limitations // under the License. package org.apache.cloudstack.api; +import java.util.ArrayList; + +import com.cloud.exception.CloudException; +import com.cloud.utils.exception.CSExceptionErrorCode; import com.cloud.utils.exception.CloudRuntimeException; @SuppressWarnings("serial") public class ServerApiException extends CloudRuntimeException { - private int _errorCode; + private ApiErrorCode _errorCode; private String _description; public ServerApiException() { - _errorCode = 0; + _errorCode = ApiErrorCode.INTERNAL_ERROR; _description = null; + setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ServerApiException.class.getName())); } - public ServerApiException(int errorCode, String description) { + public ServerApiException(ApiErrorCode errorCode, String description) { _errorCode = errorCode; _description = description; + setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ServerApiException.class.getName())); } - public int getErrorCode() { + // wrap a specific CloudRuntimeException to a ServerApiException + public ServerApiException(ApiErrorCode errorCode, String description, Throwable cause){ + super(description, cause); + _errorCode = errorCode; + _description = description; + if (cause instanceof CloudRuntimeException || cause instanceof CloudException ) { + CloudRuntimeException rt = (CloudRuntimeException) cause; + ArrayList idList = rt.getIdProxyList(); + if (idList != null) { + for (int i = 0; i < idList.size(); i++) { + addProxyObject(idList.get(i)); + } + } + setCSErrorCode(rt.getCSErrorCode()); + } + } + + public ApiErrorCode getErrorCode() { return _errorCode; } - public void setErrorCode(int errorCode) { + public void setErrorCode(ApiErrorCode errorCode) { _errorCode = errorCode; } diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java index f93787b7bc5..a13cf6253a7 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java @@ -151,7 +151,7 @@ public class CreateAccountCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a user account"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a user account"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java index a1d9b6419cb..86ccb4ba20b 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java @@ -91,7 +91,7 @@ public class DeleteAccountCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete user account and all corresponding users"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete user account and all corresponding users"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java index f0a5e7078b7..318dfda7ded 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java @@ -115,7 +115,7 @@ public class DisableAccountCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, lockRequested == true ? "Failed to lock account" : "Failed to disable account" ); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, lockRequested == true ? "Failed to lock account" : "Failed to disable account" ); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java index 4aa1e4fc1b9..2688ef1510a 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.account; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -95,7 +96,7 @@ public class EnableAccountCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to enable account"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable account"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/LockAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/LockAccountCmd.java index 34e9e53b84d..c67e8463228 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/account/LockAccountCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/account/LockAccountCmd.java @@ -84,7 +84,7 @@ public class LockAccountCmd extends BaseCmd { // response.setResponseName(getCommandName()); // this.setResponseObject(response); // } else { -// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to lock account"); +// throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to lock account"); // } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java index f1340464d6b..ea6d9078ed6 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java @@ -22,6 +22,7 @@ import java.util.Map; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -125,7 +126,7 @@ public class UpdateAccountCmd extends BaseCmd{ response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update account"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update account"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java index a119d0f44bf..8c987228022 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java @@ -20,6 +20,7 @@ package org.apache.cloudstack.api.command.admin.autoscale; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -86,7 +87,7 @@ public class CreateCounterCmd extends BaseAsyncCreateCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create Counter with name " + getName()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Counter with name " + getName()); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/autoscale/DeleteCounterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/autoscale/DeleteCounterCmd.java index 9304eeb7b93..2fde0617693 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/autoscale/DeleteCounterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/autoscale/DeleteCounterCmd.java @@ -20,6 +20,7 @@ package org.apache.cloudstack.api.command.admin.autoscale; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -56,7 +57,7 @@ public class DeleteCounterCmd extends BaseAsyncCmd { result = _autoScaleService.deleteCounter(getId()); } catch (ResourceInUseException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_IN_USE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage()); } if (result) { @@ -64,7 +65,7 @@ public class DeleteCounterCmd extends BaseAsyncCmd { this.setResponseObject(response); } else { s_logger.warn("Failed to delete counter with Id: " + getId()); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete counter."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete counter."); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java index 28bf72ddba7..c64883c16cf 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java @@ -156,7 +156,7 @@ public class AddClusterCmd extends BaseCmd { clusterResponses.add(clusterResponse); } } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add cluster"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add cluster"); } response.setResponses(clusterResponses); @@ -165,10 +165,10 @@ public class AddClusterCmd extends BaseCmd { this.setResponseObject(response); } catch (DiscoveryException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (ResourceInUseException ex) { s_logger.warn("Exception: ", ex); - ServerApiException e = new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + ServerApiException e = new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); for (String proxyObj : ex.getIdProxyList()) { e.addProxyObject(proxyObj); } diff --git a/api/src/org/apache/cloudstack/api/command/admin/cluster/DeleteClusterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/cluster/DeleteClusterCmd.java index f0b40cb6b03..93103d3f60e 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/cluster/DeleteClusterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/cluster/DeleteClusterCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.cluster; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -70,7 +71,7 @@ public class DeleteClusterCmd extends BaseCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete cluster"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete cluster"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java index 03b43def3ca..d6ec7188d0b 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.cluster; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -112,7 +113,7 @@ public class UpdateClusterCmd extends BaseCmd { clusterResponse.setResponseName(getCommandName()); this.setResponseObject(clusterResponse); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update cluster"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update cluster"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java b/api/src/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java index 79693e76f84..1c435178efa 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.config; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -76,7 +77,7 @@ public class UpdateCfgCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update config"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update config"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/config/UpdateHypervisorCapabilitiesCmd.java b/api/src/org/apache/cloudstack/api/command/admin/config/UpdateHypervisorCapabilitiesCmd.java index 82880c1fbae..19587f4483c 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/config/UpdateHypervisorCapabilitiesCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/config/UpdateHypervisorCapabilitiesCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.config; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -86,7 +87,7 @@ public class UpdateHypervisorCapabilitiesCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update hypervisor capabilities"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update hypervisor capabilities"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java b/api/src/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java index 0e6ae32583b..61614d171f0 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java @@ -84,7 +84,7 @@ public class CreateDomainCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create domain"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create domain"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java b/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java index 7009e70ca32..3fda9608c13 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java @@ -93,7 +93,7 @@ public class DeleteDomainCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete domain"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete domain"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java b/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java index cc5926cace1..607120c1886 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java @@ -83,7 +83,7 @@ public class UpdateDomainCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update domain"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java index 0a0a98c1c45..77296c72a4a 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java @@ -22,6 +22,7 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -148,7 +149,7 @@ public class AddHostCmd extends BaseCmd { hostResponses.add(hostResponse); } } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add host"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add host"); } response.setResponses(hostResponses); @@ -157,7 +158,7 @@ public class AddHostCmd extends BaseCmd { this.setResponseObject(response); } catch (DiscoveryException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java index 579e286f884..3bcee811151 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java @@ -84,11 +84,11 @@ public class AddSecondaryStorageCmd extends BaseCmd { this.setResponseObject(hostResponse); } } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add secondary storage"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); } } catch (DiscoveryException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java index 93dca9140f9..8c617c03c76 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.host; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -104,7 +105,7 @@ public class CancelMaintenanceCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to cancel host maintenance"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to cancel host maintenance"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/DeleteHostCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/DeleteHostCmd.java index 5103f986e10..c2b731b8407 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/host/DeleteHostCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/host/DeleteHostCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.HostResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -84,7 +85,7 @@ public class DeleteHostCmd extends BaseCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete host"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete host"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java index 385e2aef415..80b53aa1362 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.host; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -104,7 +105,7 @@ public class PrepareForMaintenanceCmd extends BaseAsyncCmd { response.setResponseName("host"); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to prepare host for maintenance"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to prepare host for maintenance"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java index 99e867bbebd..f42ec4b4814 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.host; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -103,11 +104,11 @@ public class ReconnectHostCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to reconnect host"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reconnect host"); } } catch (Exception ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java index 9ab27178838..c1e374e030b 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java @@ -21,6 +21,7 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -108,7 +109,7 @@ public class UpdateHostCmd extends BaseCmd { this.setResponseObject(hostResponse); } catch (Exception e) { s_logger.debug("Failed to update host:" + getId(), e); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update host:" + getId() + "," + e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update host:" + getId() + "," + e.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/AddNetworkDeviceCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/AddNetworkDeviceCmd.java index 3e1d74df405..b8f98021c40 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/AddNetworkDeviceCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/AddNetworkDeviceCmd.java @@ -21,6 +21,7 @@ import java.util.Map; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -74,9 +75,9 @@ public class AddNetworkDeviceCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException ipve) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, ipve.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage()); } catch (CloudRuntimeException cre) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, cre.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java index 6d4b962d4a1..22802f936a0 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java @@ -21,6 +21,7 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -103,7 +104,7 @@ public class AddNetworkServiceProviderCmd extends BaseAsyncCreateCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); }else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add service provider to physical network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add service provider to physical network"); } } @@ -114,7 +115,7 @@ public class AddNetworkServiceProviderCmd extends BaseAsyncCreateCmd { setEntityId(result.getId()); setEntityUuid(result.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add service provider entity to physical network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add service provider entity to physical network"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java index b97f85ec1ba..6733a35a5fd 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java @@ -225,7 +225,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network offering"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create network offering"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java index f56ae7dbf50..1b83a9114e4 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java @@ -21,6 +21,7 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -151,7 +152,7 @@ public class CreatePhysicalNetworkCmd extends BaseAsyncCreateCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); }else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create physical network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create physical network"); } } @@ -162,7 +163,7 @@ public class CreatePhysicalNetworkCmd extends BaseAsyncCreateCmd { setEntityId(result.getId()); setEntityUuid(result.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create physical network entity"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create physical network entity"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/CreateStorageNetworkIpRangeCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/CreateStorageNetworkIpRangeCmd.java index ccd92e19d67..59db3eb17c5 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/CreateStorageNetworkIpRangeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/CreateStorageNetworkIpRangeCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.network; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -110,7 +111,7 @@ public class CreateStorageNetworkIpRangeCmd extends BaseAsyncCmd { this.setResponseObject(response); } catch (Exception e) { s_logger.warn("Create storage network IP range failed", e); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/DeleteNetworkDeviceCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/DeleteNetworkDeviceCmd.java index 09451242daf..4d8d18e59ba 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/DeleteNetworkDeviceCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/DeleteNetworkDeviceCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.network; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -65,12 +66,12 @@ public class DeleteNetworkDeviceCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete network device:" + getId()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete network device:" + getId()); } } catch (InvalidParameterValueException ipve) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, ipve.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage()); } catch (CloudRuntimeException cre) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, cre.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/DeleteNetworkOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/DeleteNetworkOfferingCmd.java index c13088f6123..69f24b419c0 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/DeleteNetworkOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/DeleteNetworkOfferingCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.network; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -70,7 +71,7 @@ public class DeleteNetworkOfferingCmd extends BaseCmd{ SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete service offering"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete service offering"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/DeleteNetworkServiceProviderCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/DeleteNetworkServiceProviderCmd.java index bc744399a33..f0d2a128acc 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/DeleteNetworkServiceProviderCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/DeleteNetworkServiceProviderCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.network; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -76,14 +77,14 @@ public class DeleteNetworkServiceProviderCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete network service provider"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete network service provider"); } } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java index 5f86efa9ad8..178ccb8e0b7 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java @@ -70,7 +70,7 @@ public class DeletePhysicalNetworkCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete physical network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete physical network"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/DeleteStorageNetworkIpRangeCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/DeleteStorageNetworkIpRangeCmd.java index 1873fc7d6ef..5fa26f69a48 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/DeleteStorageNetworkIpRangeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/DeleteStorageNetworkIpRangeCmd.java @@ -70,7 +70,7 @@ public class DeleteStorageNetworkIpRangeCmd extends BaseAsyncCmd { this.setResponseObject(response); } catch (Exception e) { s_logger.warn("Failed to delete storage network ip range " + getId(), e); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/ListNetworkDeviceCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/ListNetworkDeviceCmd.java index 742ff1f74af..11e74fbb8ce 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/ListNetworkDeviceCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/ListNetworkDeviceCmd.java @@ -23,6 +23,7 @@ import java.util.Map; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.APICommand; @@ -85,9 +86,9 @@ public class ListNetworkDeviceCmd extends BaseListCmd { listResponse.setResponseName(getCommandName()); this.setResponseObject(listResponse); } catch (InvalidParameterValueException ipve) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, ipve.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage()); } catch (CloudRuntimeException cre) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, cre.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/ListPhysicalNetworksCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/ListPhysicalNetworksCmd.java index a301ac004ea..3331d48103a 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/ListPhysicalNetworksCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/ListPhysicalNetworksCmd.java @@ -23,6 +23,7 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.APICommand; @@ -100,7 +101,7 @@ public class ListPhysicalNetworksCmd extends BaseListCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); }else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to search for physical networks"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to search for physical networks"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/ListStorageNetworkIpRangeCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/ListStorageNetworkIpRangeCmd.java index 8fcaf4958b1..b5045bb99fd 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/ListStorageNetworkIpRangeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/ListStorageNetworkIpRangeCmd.java @@ -88,7 +88,7 @@ public class ListStorageNetworkIpRangeCmd extends BaseListCmd { this.setResponseObject(response); } catch (Exception e) { s_logger.warn("Failed to list storage network ip range for rangeId=" + getRangeId() + " podId=" + getPodId() + " zoneId=" + getZoneId()); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/UpdateNetworkOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/UpdateNetworkOfferingCmd.java index dc2f3099206..ca4709deb2b 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/UpdateNetworkOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/UpdateNetworkOfferingCmd.java @@ -102,7 +102,7 @@ public class UpdateNetworkOfferingCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update network offering"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network offering"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/UpdateNetworkServiceProviderCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/UpdateNetworkServiceProviderCmd.java index b770ea26c12..d64fd0796ee 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/UpdateNetworkServiceProviderCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/UpdateNetworkServiceProviderCmd.java @@ -21,6 +21,7 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -88,7 +89,7 @@ public class UpdateNetworkServiceProviderCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); }else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update service provider"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update service provider"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/UpdateStorageNetworkIpRangeCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/UpdateStorageNetworkIpRangeCmd.java index d6d0b92e4b7..d49d3c4e911 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/UpdateStorageNetworkIpRangeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/UpdateStorageNetworkIpRangeCmd.java @@ -96,7 +96,7 @@ public class UpdateStorageNetworkIpRangeCmd extends BaseAsyncCmd { this.setResponseObject(response); } catch (Exception e) { s_logger.warn("Update storage network IP range failed", e); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java index 08101dc4137..6c3630690f7 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -115,7 +116,7 @@ public class CreateDiskOfferingCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create disk offering"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create disk offering"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java index f93c2a88ce2..54151fe13b9 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -162,7 +163,7 @@ public class CreateServiceOfferingCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create service offering"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create service offering"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/offering/DeleteDiskOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/offering/DeleteDiskOfferingCmd.java index 85e034f6191..3f854637b8c 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/offering/DeleteDiskOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/offering/DeleteDiskOfferingCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -70,7 +71,7 @@ public class DeleteDiskOfferingCmd extends BaseCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete disk offering"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete disk offering"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/offering/DeleteServiceOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/offering/DeleteServiceOfferingCmd.java index d1ea4de0504..0a8949b9071 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/offering/DeleteServiceOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/offering/DeleteServiceOfferingCmd.java @@ -68,7 +68,7 @@ public class DeleteServiceOfferingCmd extends BaseCmd{ SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete service offering"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete service offering"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java index 8db731d3b31..734b18bfb93 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java @@ -18,6 +18,7 @@ package org.apache.cloudstack.api.command.admin.offering; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -91,7 +92,7 @@ public class UpdateDiskOfferingCmd extends BaseCmd{ response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update disk offering"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update disk offering"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.java index 38220b90673..9dddd7d6718 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.java @@ -89,7 +89,7 @@ public class UpdateServiceOfferingCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update service offering"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update service offering"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/pod/CreatePodCmd.java b/api/src/org/apache/cloudstack/api/command/admin/pod/CreatePodCmd.java index 331968b00db..95d9e53be75 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/pod/CreatePodCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/pod/CreatePodCmd.java @@ -111,7 +111,7 @@ public class CreatePodCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create pod"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create pod"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/pod/DeletePodCmd.java b/api/src/org/apache/cloudstack/api/command/admin/pod/DeletePodCmd.java index 8c64a8dad33..4080a7c46ee 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/pod/DeletePodCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/pod/DeletePodCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.pod; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -70,7 +71,7 @@ public class DeletePodCmd extends BaseCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete pod"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete pod"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/pod/UpdatePodCmd.java b/api/src/org/apache/cloudstack/api/command/admin/pod/UpdatePodCmd.java index ca5e03953a3..c99da9d8199 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/pod/UpdatePodCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/pod/UpdatePodCmd.java @@ -110,7 +110,7 @@ public class UpdatePodCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update pod"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update pod"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/resource/UploadCustomCertificateCmd.java b/api/src/org/apache/cloudstack/api/command/admin/resource/UploadCustomCertificateCmd.java index 0e559189904..97ec1dcee45 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/resource/UploadCustomCertificateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/resource/UploadCustomCertificateCmd.java @@ -99,7 +99,7 @@ public class UploadCustomCertificateCmd extends BaseAsyncCmd { response.setObjectName("customcertificate"); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to upload custom certificate"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upload custom certificate"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java b/api/src/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java index be6be26a36f..766e19cbe57 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.router; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -120,7 +121,7 @@ public class ConfigureVirtualRouterElementCmd extends BaseAsyncCmd { routerResponse.setResponseName(getCommandName()); this.setResponseObject(routerResponse); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to configure the virtual router provider"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure the virtual router provider"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java b/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java index f6a7b744ca3..54a840987df 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java @@ -82,7 +82,7 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); }else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network"); } } @@ -93,7 +93,7 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd { setEntityId(result.getId()); setEntityUuid(result.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java index 1157aaa7b93..1645456bffb 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.router; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -104,7 +105,7 @@ public class DestroyRouterCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to destroy router"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to destroy router"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java index 9c50d2ffb0f..a095fce9cb9 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java @@ -98,7 +98,7 @@ public class RebootRouterCmd extends BaseAsyncCmd { response.setResponseName("router"); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to reboot router"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reboot router"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java index f1f3f681829..595afc76d12 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java @@ -102,7 +102,7 @@ public class StartRouterCmd extends BaseAsyncCmd { routerResponse.setResponseName(getCommandName()); this.setResponseObject(routerResponse); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to start router"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start router"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java index 2d1b609aa5d..571b2c19977 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.router; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -109,7 +110,7 @@ public class StopRouterCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to stop router"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to stop router"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/UpgradeRouterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/router/UpgradeRouterCmd.java index e2b020e09f9..f8742a2cefb 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/router/UpgradeRouterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/router/UpgradeRouterCmd.java @@ -81,7 +81,7 @@ public class UpgradeRouterCmd extends BaseCmd { routerResponse.setResponseName(getCommandName()); this.setResponseObject(routerResponse); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to upgrade router"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade router"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java index 13f066a6e57..ec62858f597 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java @@ -31,6 +31,7 @@ import static org.apache.cloudstack.api.BaseCmd.CommandType.STRING; import static org.apache.cloudstack.api.BaseCmd.CommandType.BOOLEAN; import static com.cloud.user.Account.ACCOUNT_ID_SYSTEM; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -93,12 +94,12 @@ public final class AddS3Cmd extends BaseCmd { result = _resourceService.discoverS3(this); if (result == null) { - throw new ServerApiException(INTERNAL_ERROR, "Failed to add S3."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add S3."); } } catch (DiscoveryException e) { - throw new ServerApiException(INTERNAL_ERROR, "Failed to add S3 due to " + e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add S3 due to " + e.getMessage()); } diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java index 24ef48be222..59a2164e4d6 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.storage; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -107,7 +108,7 @@ public class CancelPrimaryStorageMaintenanceCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to cancel primary storage maintenance"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to cancel primary storage maintenance"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java index 78a142ac449..b5068115eb1 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java @@ -122,17 +122,17 @@ public class CreateStoragePoolCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add storage pool"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add storage pool"); } } catch (ResourceUnavailableException ex1) { s_logger.warn("Exception: ", ex1); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex1.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex1.getMessage()); }catch (ResourceInUseException ex2) { s_logger.warn("Exception: ", ex2); - throw new ServerApiException(BaseCmd.RESOURCE_IN_USE_ERROR, ex2.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex2.getMessage()); } catch (UnknownHostException ex3) { s_logger.warn("Exception: ", ex3); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex3.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex3.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/DeletePoolCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/DeletePoolCmd.java index 1510f7822f7..8cf4a4b7970 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/storage/DeletePoolCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/storage/DeletePoolCmd.java @@ -78,9 +78,9 @@ public class DeletePoolCmd extends BaseCmd { } else { StoragePool pool = _storageService.getStoragePool(id); if (pool != null && pool.getStatus() == StoragePoolStatus.Removed) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to finish storage pool removal. The storage pool will not be used but cleanup is needed"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to finish storage pool removal. The storage pool will not be used but cleanup is needed"); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete storage pool"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete storage pool"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java index 6a4175516cc..ab9c226909d 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.storage; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -105,7 +106,7 @@ public class PreparePrimaryStorageForMaintenanceCmd extends BaseAsyncCmd { response.setResponseName("storagepool"); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to prepare primary storage for maintenance"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to prepare primary storage for maintenance"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java index 806df561397..b60ed7f9767 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java @@ -78,7 +78,7 @@ public class UpdateStoragePoolCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update storage pool"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update storage pool"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java b/api/src/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java index 23a00ca04dc..61f903e9c3c 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java @@ -92,12 +92,12 @@ public class AddSwiftCmd extends BaseCmd { swiftResponse.setObjectName("swift"); this.setResponseObject(swiftResponse); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Swift"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Swift"); } } catch (DiscoveryException ex) { String errMsg = "Failed to add Swift due to " + ex.toString(); s_logger.warn(errMsg, ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, errMsg); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errMsg); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java index ad0f09cba46..dc53ea751b4 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java @@ -95,7 +95,7 @@ public class DestroySystemVmCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to destroy system vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Fail to destroy system vm"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java index dd844acd17f..909fe20f883 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.systemvm; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -116,20 +117,20 @@ public class MigrateSystemVMCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to migrate the system vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate the system vm"); } } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException e) { s_logger.warn("Exception: ", e); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } catch (ManagementServerException e) { s_logger.warn("Exception: ", e); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } catch (VirtualMachineMigrationException e) { s_logger.warn("Exception: ", e); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java index 49e895b22fe..2e7b5303395 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.systemvm; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -105,7 +106,7 @@ public class RebootSystemVmCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to reboot system vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Fail to reboot system vm"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java index 70ab5f38720..40f9d62aa64 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.systemvm; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -109,7 +110,7 @@ public class StartSystemVMCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to start system vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Fail to start system vm"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java index af2bd3ad64f..134043cb388 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java @@ -112,7 +112,7 @@ public class StopSystemVmCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to stop system vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Fail to stop system vm"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java index 290c3603f1f..14046f39aaf 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java @@ -94,7 +94,7 @@ public class UpgradeSystemVMCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to reboot system vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Fail to reboot system vm"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/usage/AddTrafficTypeCmd.java b/api/src/org/apache/cloudstack/api/command/admin/usage/AddTrafficTypeCmd.java index 5dca9d2d4c1..a7336245366 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/usage/AddTrafficTypeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/usage/AddTrafficTypeCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.PhysicalNetworkResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -123,7 +124,7 @@ public class AddTrafficTypeCmd extends BaseAsyncCreateCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); }else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add traffic type to physical network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add traffic type to physical network"); } } @@ -134,7 +135,7 @@ public class AddTrafficTypeCmd extends BaseAsyncCreateCmd { setEntityId(result.getId()); setEntityUuid(result.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add traffic type to physical network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add traffic type to physical network"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficTypeCmd.java b/api/src/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficTypeCmd.java index bb665fbfd58..526921830ec 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficTypeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficTypeCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.TrafficTypeResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -73,7 +74,7 @@ public class DeleteTrafficTypeCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); }else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete traffic type"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete traffic type"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/usage/UpdateTrafficTypeCmd.java b/api/src/org/apache/cloudstack/api/command/admin/usage/UpdateTrafficTypeCmd.java index 279c2b858d3..fca07028160 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/usage/UpdateTrafficTypeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/usage/UpdateTrafficTypeCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.usage; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -95,7 +96,7 @@ public class UpdateTrafficTypeCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); }else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update traffic type"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update traffic type"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java b/api/src/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java index 2045abf4e93..1f1e3abc1af 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.user; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -137,7 +138,7 @@ public class CreateUserCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a user"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a user"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java b/api/src/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java index a43501e7641..74a073c72d9 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.user; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -76,7 +77,7 @@ public class DeleteUserCmd extends BaseCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete user"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete user"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java b/api/src/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java index f483e628928..6b59de5672d 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.user; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -92,7 +93,7 @@ public class DisableUserCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disable user"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to disable user"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java b/api/src/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java index e444aa395d2..bcd0f43e03a 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java @@ -76,7 +76,7 @@ public class EnableUserCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to enable user"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable user"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/user/LockUserCmd.java b/api/src/org/apache/cloudstack/api/command/admin/user/LockUserCmd.java index 622b4e9a023..1b00bfd29ca 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/user/LockUserCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/user/LockUserCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.user; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -77,7 +78,7 @@ public class LockUserCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to lock user"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to lock user"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java b/api/src/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java index 170d852ff58..00bfccc1038 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java @@ -132,7 +132,7 @@ public class UpdateUserCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update user"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update user"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java index c9717480e44..9ac1e253bfe 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java @@ -169,14 +169,14 @@ public class CreateVlanIpRangeCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); }else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create vlan ip range"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create vlan ip range"); } } catch (ConcurrentOperationException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (InsufficientCapacityException ex) { s_logger.info(ex); - throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/vlan/DeleteVlanIpRangeCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vlan/DeleteVlanIpRangeCmd.java index f12b2175aef..d45082a2ace 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/vlan/DeleteVlanIpRangeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/vlan/DeleteVlanIpRangeCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.VlanIpRangeResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -70,7 +71,7 @@ public class DeleteVlanIpRangeCmd extends BaseCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete vlan ip range"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete vlan ip range"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java index 3482ec756fb..525e8d72f8f 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java @@ -101,14 +101,14 @@ public class AssignVMCmd extends BaseCmd { try { UserVm userVm = _userVmService.moveVMToUser(this); if (userVm == null){ - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to move vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm"); } UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", userVm).get(0); response.setResponseName(DeployVMCmd.getResultObjectName()); this.setResponseObject(response); }catch (Exception e){ e.printStackTrace(); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to move vm " + e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm " + e.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/vm/MigrateVMCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vm/MigrateVMCmd.java index 5bb694da655..e1f20a8e9d3 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/vm/MigrateVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/vm/MigrateVMCmd.java @@ -150,20 +150,20 @@ public class MigrateVMCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to migrate vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate vm"); } } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException e) { s_logger.warn("Exception: ", e); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } catch (ManagementServerException e) { s_logger.warn("Exception: ", e); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } catch (VirtualMachineMigrationException e) { s_logger.warn("Exception: ", e); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/vm/RecoverVMCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vm/RecoverVMCmd.java index f8308614b89..be4d10b8b5f 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/vm/RecoverVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/vm/RecoverVMCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.vm; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -77,7 +78,7 @@ public class RecoverVMCmd extends BaseCmd { recoverVmResponse.setResponseName(getCommandName()); this.setResponseObject(recoverVmResponse); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to recover vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to recover vm"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayCmd.java index 5bb76ab034b..392b6276bc9 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayCmd.java @@ -21,6 +21,7 @@ import org.apache.cloudstack.api.response.VpcResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; @@ -115,17 +116,17 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd { } catch (InsufficientCapacityException ex){ s_logger.info(ex); s_logger.trace(ex); - throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } if (result != null) { this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private gateway"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private gateway"); } } @@ -138,7 +139,7 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private gateway"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private gateway"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java index 273f7c05233..8ccb9d5e68c 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java @@ -72,7 +72,7 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd{ this.setEntityId(vpcOff.getId()); this.setEntityUuid(vpcOff.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a VPC offering"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a VPC offering"); } } @@ -84,7 +84,7 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd{ response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create VPC offering"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPC offering"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/vpc/DeletePrivateGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vpc/DeletePrivateGatewayCmd.java index 4a1e8d05912..2b0e1a6a193 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/vpc/DeletePrivateGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/vpc/DeletePrivateGatewayCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.PrivateGatewayResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -87,7 +88,7 @@ public class DeletePrivateGatewayCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete private gateway"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete private gateway"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/vpc/DeleteVPCOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vpc/DeleteVPCOfferingCmd.java index 231f2ee2955..9a257c24c0c 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/vpc/DeleteVPCOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/vpc/DeleteVPCOfferingCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.VpcOfferingResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -71,7 +72,7 @@ public class DeleteVPCOfferingCmd extends BaseAsyncCmd{ SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete VPC offering"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete VPC offering"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java index 65df48e3e1f..c8fa77df1ff 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java @@ -90,7 +90,7 @@ public class UpdateVPCOfferingCmd extends BaseAsyncCmd{ response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update VPC offering"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC offering"); } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java b/api/src/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java index e49f2439288..ae57fae5a8d 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.zone; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -156,7 +157,7 @@ public class CreateZoneCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a zone"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a zone"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java b/api/src/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java index d09c7fff891..e9a02accba1 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java @@ -71,7 +71,7 @@ public class DeleteZoneCmd extends BaseCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete zone"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete zone"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java index 816befbd029..59a37c96a84 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.zone; import org.apache.log4j.Logger; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -109,7 +110,7 @@ public class MarkDefaultZoneForAccountCmd extends BaseAsyncCmd { this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to mark the account with the default zone"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to mark the account with the default zone"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java b/api/src/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java index 0bfd1a31a0f..143c8f7a892 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java @@ -164,7 +164,7 @@ public class UpdateZoneCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update zone; internal error."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update zone; internal error."); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java b/api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java index 889c3697515..f62be0bf8c3 100644 --- a/api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java @@ -87,7 +87,7 @@ public class AddAccountToProjectCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add account to the project"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add account to the project"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java b/api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java index f9e967ad4c2..ef14d1ae7aa 100644 --- a/api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java @@ -76,7 +76,7 @@ public class DeleteAccountFromProjectCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete account from the project"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete account from the project"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java b/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java index 93bb2401d8f..4437191db37 100644 --- a/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java @@ -21,6 +21,7 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; @@ -219,15 +220,15 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { this.setEntityId(ip.getId()); this.setEntityUuid(ip.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to allocate ip address"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to allocate ip address"); } } catch (ConcurrentOperationException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (InsufficientAddressCapacityException ex) { s_logger.info(ex); s_logger.trace(ex); - throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } @@ -249,7 +250,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { ipResponse.setResponseName(getCommandName()); this.setResponseObject(ipResponse); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to assign ip address"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign ip address"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java b/api/src/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java index 20ccd89ba84..c208a1a3d92 100644 --- a/api/src/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java @@ -75,7 +75,7 @@ public class DisassociateIPAddrCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disassociate ip address"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to disassociate ip address"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java index e92721d77bf..987d305b4b0 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java @@ -157,7 +157,7 @@ public class CreateAutoScalePolicyCmd extends BaseAsyncCreateCmd { this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create AutoScale Policy"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create AutoScale Policy"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java index e3d47a09c7d..400be5db3f1 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java @@ -159,7 +159,7 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd { this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create Autoscale Vm Group"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Autoscale Vm Group"); } } @@ -182,7 +182,7 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd { } finally { if (!success || vmGroup == null) { _autoScaleService.deleteAutoScaleVmGroup(getEntityId()); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create Autoscale Vm Group"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Autoscale Vm Group"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java index 25bb03b778f..39814e7b9ce 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java @@ -22,6 +22,7 @@ import java.util.Map; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -231,7 +232,7 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd { this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create Autoscale Vm Profile"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Autoscale Vm Profile"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java index 58926f2a4ff..89da2345134 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java @@ -22,6 +22,7 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -74,7 +75,7 @@ public class CreateConditionCmd extends BaseAsyncCreateCmd { this.setEntityId(condition.getId()); this.setEntityUuid(condition.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create condition."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create condition."); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScalePolicyCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScalePolicyCmd.java index 483a87ac892..aa236ee082e 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScalePolicyCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScalePolicyCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.AutoScalePolicyResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -92,7 +93,7 @@ public class DeleteAutoScalePolicyCmd extends BaseAsyncCmd { this.setResponseObject(response); } else { s_logger.warn("Failed to delete autoscale policy " + getId()); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete AutoScale Policy"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete AutoScale Policy"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmGroupCmd.java index 1d78fe80395..54eb7462750 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmGroupCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -92,7 +93,7 @@ public class DeleteAutoScaleVmGroupCmd extends BaseAsyncCmd { this.setResponseObject(response); } else { s_logger.warn("Failed to delete autoscale vm group " + getId()); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete autoscale vm group"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete autoscale vm group"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmProfileCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmProfileCmd.java index e49f0c862a3..726f006ef02 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmProfileCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmProfileCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -91,7 +92,7 @@ public class DeleteAutoScaleVmProfileCmd extends BaseAsyncCmd { this.setResponseObject(response); } else { s_logger.warn("Failed to delete autoscale vm profile " + getId()); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete autoscale vm profile"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete autoscale vm profile"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteConditionCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteConditionCmd.java index a1fba2e3725..5ce1ee27a73 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteConditionCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/DeleteConditionCmd.java @@ -21,6 +21,7 @@ import org.apache.cloudstack.api.response.ConditionResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -57,14 +58,14 @@ public class DeleteConditionCmd extends BaseAsyncCmd { result = _autoScaleService.deleteCondition(getId()); } catch (ResourceInUseException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_IN_USE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage()); } if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { s_logger.warn("Failed to delete condition " + getId()); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete condition."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete condition."); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/DisableAutoScaleVmGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/DisableAutoScaleVmGroupCmd.java index 2aba82c2a93..f4f9212979e 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/DisableAutoScaleVmGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/DisableAutoScaleVmGroupCmd.java @@ -20,6 +20,7 @@ package org.apache.cloudstack.api.command.user.autoscale; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -56,7 +57,7 @@ public class DisableAutoScaleVmGroupCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disable AutoScale Vm Group"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to disable AutoScale Vm Group"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/EnableAutoScaleVmGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/EnableAutoScaleVmGroupCmd.java index db7acdf5d98..80ac818d263 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/EnableAutoScaleVmGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/EnableAutoScaleVmGroupCmd.java @@ -52,7 +52,7 @@ public class EnableAutoScaleVmGroupCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to enable AutoScale Vm Group"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable AutoScale Vm Group"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScalePolicyCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScalePolicyCmd.java index 56d71078ece..6a55a4aa1e6 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScalePolicyCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScalePolicyCmd.java @@ -23,6 +23,7 @@ import org.apache.cloudstack.api.response.ConditionResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -68,7 +69,7 @@ public class UpdateAutoScalePolicyCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update autoscale policy"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update autoscale policy"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java index ea5b6a9f489..fc6a7c6b861 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java @@ -75,7 +75,7 @@ public class UpdateAutoScaleVmGroupCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update autoscale VmGroup"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update autoscale VmGroup"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java index c8ef8b11198..570ed0beb3d 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java @@ -73,7 +73,7 @@ public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update autoscale vm profile"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update autoscale vm profile"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java index 7039b417ced..0dcba5f4d5b 100644 --- a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java @@ -23,6 +23,7 @@ import org.apache.cloudstack.api.response.IPAddressResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; @@ -134,7 +135,7 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal } finally { if (!success || rule == null) { _firewallService.revokeFirewallRule(getEntityId(), true); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create firewall rule"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create firewall rule"); } } } @@ -231,7 +232,7 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal if (getSourceCidrList() != null) { for (String cidr: getSourceCidrList()){ if (!NetUtils.isValidCIDR(cidr)){ - throw new ServerApiException(BaseCmd.PARAM_ERROR, "Source cidrs formatting error " + cidr); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Source cidrs formatting error " + cidr); } } } @@ -243,7 +244,7 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal } catch (NetworkRuleConflictException ex) { s_logger.info("Network rule conflict: " + ex.getMessage()); s_logger.trace("Network Rule Conflict: ", ex); - throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java index 1feefde9a1a..7d8dbb0bbdf 100644 --- a/api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java @@ -185,7 +185,7 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P _rulesService.revokePortForwardingRule(getEntityId(), true); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to apply port forwarding rule"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to apply port forwarding rule"); } } } @@ -302,7 +302,7 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P } catch (NetworkRuleConflictException ex) { s_logger.info("Network rule conflict: " , ex); s_logger.trace("Network Rule Conflict: ", ex); - throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java index 5655b5e430f..8b0a5c16e07 100644 --- a/api/src/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java @@ -95,7 +95,7 @@ public class DeleteFirewallRuleCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete firewall rule"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete firewall rule"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java index 8f4d5996df8..e70bb1556df 100644 --- a/api/src/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java @@ -97,7 +97,7 @@ public class DeletePortForwardingRuleCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete port forwarding rule"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete port forwarding rule"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java index a52ebb77257..2eafaaf7293 100644 --- a/api/src/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java @@ -124,7 +124,7 @@ public class UpdatePortForwardingRuleCmd extends BaseAsyncCmd { // response.setResponseName(getName()); // this.setResponseObject(response); // } else { -// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update port forwarding rule"); +// throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update port forwarding rule"); // } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java index 1e154e2a07d..2a0b2c61617 100644 --- a/api/src/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java @@ -21,6 +21,7 @@ import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -104,10 +105,10 @@ public class AttachIsoCmd extends BaseAsyncCmd { response.setResponseName(DeployVMCmd.getResultObjectName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to attach iso"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to attach iso"); } } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to attach iso"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to attach iso"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/DeleteIsoCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/DeleteIsoCmd.java index 44efbf88f2c..4c370c70325 100644 --- a/api/src/org/apache/cloudstack/api/command/user/iso/DeleteIsoCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/iso/DeleteIsoCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.iso; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -112,7 +113,7 @@ public class DeleteIsoCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete iso"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete iso"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java index eb1c6eed2d6..c8a87cbdb3e 100644 --- a/api/src/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java @@ -21,6 +21,7 @@ import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -91,7 +92,7 @@ public class DetachIsoCmd extends BaseAsyncCmd { response.setResponseName(DeployVMCmd.getResultObjectName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to detach iso"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to detach iso"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/ExtractIsoCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/ExtractIsoCmd.java index 5f8303ec320..7f893ccd06d 100644 --- a/api/src/org/apache/cloudstack/api/command/user/iso/ExtractIsoCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/iso/ExtractIsoCmd.java @@ -126,11 +126,11 @@ public class ExtractIsoCmd extends BaseAsyncCmd { response.setObjectName("iso"); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to extract iso"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract iso"); } } catch (InternalErrorException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java index 214d18de5cc..fbc09d8bd56 100644 --- a/api/src/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java @@ -166,7 +166,7 @@ public class RegisterIsoCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to register iso"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register iso"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java index f54f8a66daa..fd1ee3e22de 100644 --- a/api/src/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.iso; import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd; import org.apache.log4j.Logger; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ServerApiException; @@ -72,7 +73,7 @@ public class UpdateIsoCmd extends BaseUpdateTemplateOrIsoCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update iso"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update iso"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/AssignToLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/AssignToLoadBalancerRuleCmd.java index 972673f4954..72c317c89d2 100644 --- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/AssignToLoadBalancerRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/AssignToLoadBalancerRuleCmd.java @@ -23,6 +23,7 @@ import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -102,7 +103,7 @@ public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to assign load balancer rule"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign load balancer rule"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java index c01e138c1d1..90e89137bf9 100644 --- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java @@ -23,6 +23,7 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -129,7 +130,7 @@ public class CreateLBStickinessPolicyCmd extends BaseAsyncCreateCmd { } } finally { if (!success || (policy == null)) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create stickiness policy "); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create stickiness policy "); } } } @@ -142,7 +143,7 @@ public class CreateLBStickinessPolicyCmd extends BaseAsyncCreateCmd { this.setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException e) { s_logger.warn("Exception: ", e); - throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java index 4e76a6b676f..b42ff4cc5f1 100644 --- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java @@ -21,6 +21,7 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -266,7 +267,7 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements // no need to apply the rule on the backend as it exists in the db only _lbService.deleteLoadBalancerRule(getEntityId(), false); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create load balancer rule"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create load balancer rule"); } } } @@ -283,10 +284,10 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements this.setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException e) { s_logger.warn("Exception: ", e); - throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } catch (InsufficientAddressCapacityException e) { s_logger.warn("Exception: ", e); - throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java index 9329bd35aba..6405dca169b 100644 --- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.LBStickinessResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -91,7 +92,7 @@ public class DeleteLBStickinessPolicyCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete load balancer stickiness policy"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete load balancer stickiness policy"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLoadBalancerRuleCmd.java index d53155f17b9..84ce225fa1e 100644 --- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLoadBalancerRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLoadBalancerRuleCmd.java @@ -89,7 +89,7 @@ public class DeleteLoadBalancerRuleCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete load balancer"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete load balancer"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java index f56f06d15c5..54c136fae6d 100644 --- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java @@ -98,7 +98,7 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to remove instance from load balancer rule"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove instance from load balancer rule"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java index 8a86f74260d..dd2b360ec23 100644 --- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java @@ -106,7 +106,7 @@ public class UpdateLoadBalancerRuleCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update load balancer rule"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update load balancer rule"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java index 1ce3458dde3..c3894c47f57 100644 --- a/api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java @@ -22,6 +22,7 @@ import org.apache.cloudstack.api.response.IPAddressResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; @@ -132,7 +133,7 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta _rulesService.revokeStaticNatRule(getEntityId(), true); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Error in creating ip forwarding rule on the domr"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Error in creating ip forwarding rule on the domr"); } } } @@ -151,7 +152,7 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta this.setEntityUuid(rule.getUuid()); } catch (NetworkRuleConflictException e) { s_logger.info("Unable to create Static Nat Rule due to ", e); - throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java index 6300a412d54..9879cf5011b 100644 --- a/api/src/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java @@ -21,6 +21,7 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -78,7 +79,7 @@ public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete ip forwarding rule"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete ip forwarding rule"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/nat/DisableStaticNatCmd.java b/api/src/org/apache/cloudstack/api/command/user/nat/DisableStaticNatCmd.java index fbd0b5ce900..eded5a10742 100644 --- a/api/src/org/apache/cloudstack/api/command/user/nat/DisableStaticNatCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/nat/DisableStaticNatCmd.java @@ -21,6 +21,7 @@ import org.apache.cloudstack.api.response.IPAddressResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -86,7 +87,7 @@ public class DisableStaticNatCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disable static nat"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to disable static nat"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java b/api/src/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java index 79a8e2bc9ff..f7cf5aad5d0 100644 --- a/api/src/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.nat; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -114,12 +115,12 @@ public class EnableStaticNatCmd extends BaseCmd{ SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to enable static nat"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable static nat"); } } catch (NetworkRuleConflictException ex) { s_logger.info("Network rule conflict: " + ex.getMessage()); s_logger.trace("Network Rule Conflict: ", ex); - throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java index 16843b56d67..d1289b8ddc6 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java @@ -23,6 +23,7 @@ import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; @@ -164,7 +165,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements FirewallR } finally { if (!success || rule == null) { _networkACLService.revokeNetworkACL(getEntityId(), true); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network ACL"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create network ACL"); } } } @@ -250,7 +251,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements FirewallR if (getSourceCidrList() != null) { for (String cidr: getSourceCidrList()){ if (!NetUtils.isValidCIDR(cidr)){ - throw new ServerApiException(BaseCmd.PARAM_ERROR, "Source cidrs formatting error " + cidr); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Source cidrs formatting error " + cidr); } } } @@ -262,7 +263,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements FirewallR } catch (NetworkRuleConflictException ex) { s_logger.info("Network rule conflict: " + ex.getMessage()); s_logger.trace("Network Rule Conflict: ", ex); - throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java index 3b2608729a4..870a591bb36 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.network; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -233,7 +234,7 @@ public class CreateNetworkCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); }else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create network"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java index 4b078ed7fe3..798bd43aa0b 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.network; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -99,7 +100,7 @@ public class DeleteNetworkACLCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete network ACL"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete network ACL"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java index df070ff8ecb..2104501d9c2 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java @@ -68,7 +68,7 @@ public class DeleteNetworkCmd extends BaseAsyncCmd{ SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete network"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/network/RestartNetworkCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/RestartNetworkCmd.java index ee9af3b0009..c6b5690aeaf 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/RestartNetworkCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/RestartNetworkCmd.java @@ -90,7 +90,7 @@ public class RestartNetworkCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to restart network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to restart network"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java index 5ab8a6035ad..978c71b946c 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.network; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -136,7 +137,7 @@ public class UpdateNetworkCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update network"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/project/ActivateProjectCmd.java b/api/src/org/apache/cloudstack/api/command/user/project/ActivateProjectCmd.java index 6cc9387ac2b..8fd52753d77 100644 --- a/api/src/org/apache/cloudstack/api/command/user/project/ActivateProjectCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/project/ActivateProjectCmd.java @@ -79,7 +79,7 @@ public class ActivateProjectCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to activate a project"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to activate a project"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java b/api/src/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java index 865f7a0aa99..095cbfc49b8 100644 --- a/api/src/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java @@ -114,7 +114,7 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a project"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a project"); } } @@ -126,7 +126,7 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd { this.setEntityId(project.getId()); this.setEntityUuid(project.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a project"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a project"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/project/DeleteProjectCmd.java b/api/src/org/apache/cloudstack/api/command/user/project/DeleteProjectCmd.java index fb41a7f14ef..6f7467fadf8 100644 --- a/api/src/org/apache/cloudstack/api/command/user/project/DeleteProjectCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/project/DeleteProjectCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -71,7 +72,7 @@ public class DeleteProjectCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete project"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete project"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/project/DeleteProjectInvitationCmd.java b/api/src/org/apache/cloudstack/api/command/user/project/DeleteProjectInvitationCmd.java index 67c7cefc252..7ed857e575b 100644 --- a/api/src/org/apache/cloudstack/api/command/user/project/DeleteProjectInvitationCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/project/DeleteProjectInvitationCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.ProjectInvitationResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -72,7 +73,7 @@ public class DeleteProjectInvitationCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete the project invitation"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete the project invitation"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/project/SuspendProjectCmd.java b/api/src/org/apache/cloudstack/api/command/user/project/SuspendProjectCmd.java index 120e4fe0c55..01e4082c193 100644 --- a/api/src/org/apache/cloudstack/api/command/user/project/SuspendProjectCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/project/SuspendProjectCmd.java @@ -69,7 +69,7 @@ public class SuspendProjectCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to suspend a project"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to suspend a project"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectCmd.java b/api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectCmd.java index bad117727e0..01f56311d17 100644 --- a/api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.project; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -97,7 +98,7 @@ public class UpdateProjectCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update a project"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update a project"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java b/api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java index 32e1a755484..637c6339521 100644 --- a/api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java @@ -92,7 +92,7 @@ public class UpdateProjectInvitationCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to join the project"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to join the project"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/resource/GetCloudIdentifierCmd.java b/api/src/org/apache/cloudstack/api/command/user/resource/GetCloudIdentifierCmd.java index 0d62c18f55d..5799db26d7a 100644 --- a/api/src/org/apache/cloudstack/api/command/user/resource/GetCloudIdentifierCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/resource/GetCloudIdentifierCmd.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -74,7 +75,7 @@ public class GetCloudIdentifierCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to get cloud identifier"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to get cloud identifier"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java b/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java index d2b6870f0ca..4aa694b6857 100644 --- a/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java @@ -123,7 +123,7 @@ public class UpdateResourceCountCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to recalculate resource counts"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to recalculate resource counts"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java b/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java index 262d12dc264..9b6359fcc4c 100644 --- a/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java @@ -100,7 +100,7 @@ public class UpdateResourceLimitCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update resource limit"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update resource limit"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java b/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java index acafcbe19a9..0551089f033 100644 --- a/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java @@ -206,7 +206,7 @@ public class AuthorizeSecurityGroupEgressCmd extends BaseAsyncCmd { SecurityGroupResponse response = _responseGenerator.createSecurityGroupResponseFromSecurityGroupRule(egressRules); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to authorize security group egress rule(s)"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to authorize security group egress rule(s)"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java b/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java index abd20fcc81d..35939d36659 100644 --- a/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java @@ -25,6 +25,7 @@ import java.util.Map; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -210,7 +211,7 @@ public class AuthorizeSecurityGroupIngressCmd extends BaseAsyncCmd { if(cidrList != null){ for(String cidr : cidrList ){ if (!NetUtils.isValidCIDR(cidr)){ - throw new ServerApiException(BaseCmd.PARAM_ERROR, cidr + " is an Invalid CIDR "); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, cidr + " is an Invalid CIDR "); } } } @@ -219,7 +220,7 @@ public class AuthorizeSecurityGroupIngressCmd extends BaseAsyncCmd { SecurityGroupResponse response = _responseGenerator.createSecurityGroupResponseFromSecurityGroupRule(ingressRules); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to authorize security group ingress rule(s)"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to authorize security group ingress rule(s)"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java index c494355e15e..5dc49291426 100644 --- a/api/src/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.securitygroup; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -116,7 +117,7 @@ public class CreateSecurityGroupCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create security group"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create security group"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java index 15a00253b63..506dc53ff23 100644 --- a/api/src/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.securitygroup; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -120,11 +121,11 @@ public class DeleteSecurityGroupCmd extends BaseCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete security group"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete security group"); } } catch (ResourceInUseException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_IN_USE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupEgressCmd.java b/api/src/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupEgressCmd.java index 53d8fcf59c7..27072fcb6c3 100644 --- a/api/src/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupEgressCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupEgressCmd.java @@ -88,7 +88,7 @@ public class RevokeSecurityGroupEgressCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to revoke security group egress rule"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to revoke security group egress rule"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupIngressCmd.java b/api/src/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupIngressCmd.java index 1f56dee9bca..70851cf1e41 100644 --- a/api/src/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupIngressCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupIngressCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.securitygroup; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -92,7 +93,7 @@ public class RevokeSecurityGroupIngressCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to revoke security group ingress rule"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to revoke security group ingress rule"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java b/api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java index 14f46540cc3..49158a64d17 100644 --- a/api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java @@ -152,7 +152,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd { this.setEntityId(snapshot.getId()); this.setEntityUuid(snapshot.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create snapshot"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot"); } } @@ -165,7 +165,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + volumeId); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + volumeId); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java b/api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java index cafb79e0523..756a93aa8f4 100644 --- a/api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java @@ -126,7 +126,7 @@ public class CreateSnapshotPolicyCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create snapshot policy"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot policy"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotCmd.java b/api/src/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotCmd.java index 6def8730cbd..dc0b8ee8138 100644 --- a/api/src/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotCmd.java @@ -94,7 +94,7 @@ public class DeleteSnapshotCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete snapshot"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete snapshot"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotPoliciesCmd.java b/api/src/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotPoliciesCmd.java index 17f28d931ea..0207f3c3416 100644 --- a/api/src/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotPoliciesCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotPoliciesCmd.java @@ -21,6 +21,7 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -80,7 +81,7 @@ public class DeleteSnapshotPoliciesCmd extends BaseCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete snapshot policy"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete snapshot policy"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java b/api/src/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java index 54338bd24e2..9c108b4904c 100644 --- a/api/src/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java @@ -26,6 +26,7 @@ import java.util.Map; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -115,7 +116,7 @@ public class CreateTagsCmd extends BaseAsyncCmd{ SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create tags"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create tags"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/tag/DeleteTagsCmd.java b/api/src/org/apache/cloudstack/api/command/user/tag/DeleteTagsCmd.java index cf2ea9ec1cb..c142f141f86 100644 --- a/api/src/org/apache/cloudstack/api/command/user/tag/DeleteTagsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/tag/DeleteTagsCmd.java @@ -26,6 +26,7 @@ import java.util.Map; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -106,7 +107,7 @@ public class DeleteTagsCmd extends BaseAsyncCmd{ SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete tags"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete tags"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java index c6461a75e28..406f32cc958 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java @@ -21,6 +21,7 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -133,11 +134,11 @@ public class CopyTemplateCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to copy template"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to copy template"); } } catch (StorageUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java index e72b49b4e4d..9723f9a14a1 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java @@ -247,7 +247,7 @@ import com.cloud.user.UserContext; this.setEntityId(template.getId()); this.setEntityUuid(template.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a template"); } } @@ -277,7 +277,7 @@ import com.cloud.user.UserContext; response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private template"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private template"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java index 26f3e841f68..8ee3041713c 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java @@ -109,7 +109,7 @@ public class DeleteTemplateCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete template"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete template"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java index 521293cb275..54f3e3782fb 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java @@ -126,11 +126,11 @@ public class ExtractTemplateCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to extract template"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract template"); } } catch (InternalErrorException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java index b3677b9d3a1..cc4c52486e7 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java @@ -24,6 +24,7 @@ import java.util.Map; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -233,11 +234,11 @@ public class RegisterTemplateCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to register template"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register template"); } } catch (URISyntaxException ex1) { s_logger.info(ex1); - throw new ServerApiException(BaseCmd.PARAM_ERROR, ex1.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex1.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java index 01ea200293e..8893e8faeef 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.template; import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd; import org.apache.log4j.Logger; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ServerApiException; @@ -73,7 +74,7 @@ public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update template"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update template"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java index e675c83dd6f..9d39f692eaf 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java @@ -364,14 +364,14 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { } } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (InsufficientCapacityException ex) { s_logger.info(ex); s_logger.trace(ex); - throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } else { result = _userVmService.getUserVm(getEntityId()); @@ -382,7 +382,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to deploy vm"); } } @@ -454,18 +454,18 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { setEntityId(vm.getId()); setEntityUuid(vm.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to deploy vm"); } } catch (InsufficientCapacityException ex) { s_logger.info(ex); s_logger.trace(ex); - throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java index db830d1a188..381f5b744b8 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java @@ -104,7 +104,7 @@ public class DestroyVMCmd extends BaseAsyncCmd { response.setResponseName("virtualmachine"); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to destroy vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to destroy vm"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java index 45ebc287913..63319dc6853 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.vm; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -107,7 +108,7 @@ public class RebootVMCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to reboot vm instance"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reboot vm instance"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java index a4c2b3772e9..2ca94bf6a89 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.vm; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -116,7 +117,7 @@ public class ResetVMPasswordCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to reset vm password"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset vm password"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java index 9b2452e355d..d906c7f6343 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.vm; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -64,7 +65,7 @@ public class RestoreVMCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to restore vm " + getVmId()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to restore vm " + getVmId()); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java index 36199d13c24..65391f7f8ff 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java @@ -125,17 +125,17 @@ public class StartVMCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to start a vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start a vm"); } } catch (ConcurrentOperationException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (StorageUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ExecutionException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java index 8e589060520..cfa89a54249 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java @@ -120,7 +120,7 @@ public class StopVMCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to stop vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to stop vm"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java index 7f1e7efdc1a..60b23389ddd 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.vm; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -126,7 +127,7 @@ public class UpdateVMCmd extends BaseCmd{ response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update vm"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java index f2c3882bd3c..6c2e0f1eb54 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java @@ -98,7 +98,7 @@ public class UpgradeVMCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to upgrade vm"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade vm"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java index 9c2c6027ac9..ea28497053d 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java @@ -99,7 +99,7 @@ public class CreateVMGroupCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create vm instance group"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create vm instance group"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vmgroup/DeleteVMGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/vmgroup/DeleteVMGroupCmd.java index 47c2f764db6..3e9d1a24afa 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vmgroup/DeleteVMGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vmgroup/DeleteVMGroupCmd.java @@ -73,7 +73,7 @@ public class DeleteVMGroupCmd extends BaseCmd{ SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete vm group"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete vm group"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vmgroup/UpdateVMGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/vmgroup/UpdateVMGroupCmd.java index 09313c0f797..eb0d747d54b 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vmgroup/UpdateVMGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vmgroup/UpdateVMGroupCmd.java @@ -80,7 +80,7 @@ public class UpdateVMGroupCmd extends BaseCmd{ response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update vm instance group"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update vm instance group"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java index e48e4e43093..e5652952a0f 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -125,7 +126,7 @@ public class AttachVolumeCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to attach volume"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to attach volume"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java index 04541b9fda7..0a0ba54e04f 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.*; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -153,7 +154,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd { this.setEntityId(volume.getId()); this.setEntityUuid(volume.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create volume"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create volume"); } } @@ -179,7 +180,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a volume"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a volume"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java index 2b2e94cab6b..6e3b4e12f7f 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -84,7 +85,7 @@ public class DeleteVolumeCmd extends BaseCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete volume"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete volume"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java index c8ecddea699..db17f58e6e6 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java @@ -132,7 +132,7 @@ public class DetachVolumeCmd extends BaseAsyncCmd { response.setResponseName("volume"); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to detach volume"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to detach volume"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/ExtractVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/ExtractVolumeCmd.java index 43b25a83663..40e46fd6b88 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/ExtractVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/ExtractVolumeCmd.java @@ -23,6 +23,7 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -148,11 +149,11 @@ public class ExtractVolumeCmd extends BaseAsyncCmd { response.setUrl(uploadInfo.getUploadUrl()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to extract volume"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract volume"); } } catch (URISyntaxException ex) { s_logger.info(ex); - throw new ServerApiException(BaseCmd.PARAM_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java index 30e672ada1b..88076dbfb8b 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.api.command.user.volume; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -98,7 +99,7 @@ public class MigrateVolumeCmd extends BaseAsyncCmd { this.setResponseObject(response); } } catch (ConcurrentOperationException e) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to migrate volume: "); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate volume: "); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java index e42bf3565cc..ff004831516 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.*; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.BaseListTaggedResourcesCmd; @@ -64,7 +65,7 @@ public class ResizeVolumeCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.DISK_OFFERING_ID, entityType=DiskOfferingResponse.class, type=CommandType.UUID, required=false, description="new disk offering id") private Long newDiskOfferingId; - + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -72,7 +73,7 @@ public class ResizeVolumeCmd extends BaseAsyncCmd { public Long getEntityId() { return id; } - + public Long getSize() { return size; } @@ -85,7 +86,7 @@ public class ResizeVolumeCmd extends BaseAsyncCmd { return newDiskOfferingId; } - + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -94,7 +95,7 @@ public class ResizeVolumeCmd extends BaseAsyncCmd { public String getCommandName() { return s_name; } - + @Override public AsyncJob.Type getInstanceType() { return AsyncJob.Type.Volume; @@ -136,7 +137,7 @@ public class ResizeVolumeCmd extends BaseAsyncCmd { public String getEventDescription() { return "Volume Id: " + getEntityId() + " to size " + getSize() + "G" ; } - + @Override public void execute(){ UserContext.current().setEventDetails("Volume Id: " + getEntityId() + " to size " + getSize() + "G"); @@ -147,7 +148,7 @@ public class ResizeVolumeCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to resize volume"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to resize volume"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java index 4167ffd6460..e2c2c5b6d3a 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java @@ -112,7 +112,7 @@ public class UploadVolumeCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to upload volume"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upload volume"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java index 96de56a5be5..adeec0d0425 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.vpc; import org.apache.cloudstack.api.response.PrivateGatewayResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; @@ -71,7 +72,7 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{ } catch (NetworkRuleConflictException ex) { s_logger.info("Network rule conflict: " + ex.getMessage()); s_logger.trace("Network rule conflict: ", ex); - throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } } @@ -105,7 +106,7 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{ } finally { if (!success || route == null) { _vpcService.revokeStaticRoute(getEntityId()); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create static route"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create static route"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java index 8a2e1f641fb..ccd8675e50d 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java @@ -24,6 +24,7 @@ import org.apache.cloudstack.api.response.VpcOfferingResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -126,7 +127,7 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ this.setEntityId(vpc.getId()); this.setEntityUuid(vpc.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a VPC"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a VPC"); } } @@ -139,14 +140,14 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ } } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (InsufficientCapacityException ex) { s_logger.info(ex); s_logger.trace(ex); - throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } if (vpc != null) { @@ -154,7 +155,7 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create VPC"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPC"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/DeleteStaticRouteCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/DeleteStaticRouteCmd.java index c9e4463db14..02d342e5c80 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/DeleteStaticRouteCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/DeleteStaticRouteCmd.java @@ -95,7 +95,7 @@ public class DeleteStaticRouteCmd extends BaseAsyncCmd{ SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete static route"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete static route"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/DeleteVPCCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/DeleteVPCCmd.java index ed4e754f736..132556c87b7 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/DeleteVPCCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/DeleteVPCCmd.java @@ -71,14 +71,14 @@ public class DeleteVPCCmd extends BaseAsyncCmd{ SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete VPC"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete VPC"); } }catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java index 4a23e6e6595..f28c4cb55bb 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java @@ -78,18 +78,18 @@ public class RestartVPCCmd extends BaseAsyncCmd{ SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to restart VPC"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to restart VPC"); } } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (InsufficientCapacityException ex) { s_logger.info(ex); s_logger.trace(ex); - throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java index 2dc64dba267..d34f7bf7bf3 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.vpc; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -92,7 +93,7 @@ public class UpdateVPCCmd extends BaseAsyncCmd{ response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update VPC"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java index f2d19a7cce6..479e990494d 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.vpn; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCreateCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -119,7 +120,7 @@ public class AddVpnUserCmd extends BaseAsyncCreateCmd { VpnUser vpnUser = _entityMgr.findById(VpnUser.class, getEntityId()); Account account = _entityMgr.findById(Account.class, vpnUser.getAccountId()); if (!_ravService.applyVpnUsers(vpnUser.getAccountId(), userName)) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add vpn user"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user"); } VpnUsersResponse vpnResponse = new VpnUsersResponse(); @@ -144,7 +145,7 @@ public class AddVpnUserCmd extends BaseAsyncCreateCmd { VpnUser vpnUser = _ravService.addVpnUser(owner.getId(), userName, password); if (vpnUser == null) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add vpn user"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user"); } setEntityId(vpnUser.getId()); setEntityUuid(vpnUser.getUuid()); diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java index b517af883c3..ae09ef79894 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java @@ -148,12 +148,12 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd { this.setEntityUuid(ipAddr.getUuid()); } } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create remote access vpn"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create remote access vpn"); } } catch (NetworkRuleConflictException e) { s_logger.info("Network rule conflict: " + e.getMessage()); s_logger.trace("Network Rule Conflict: ", e); - throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } } @@ -166,11 +166,11 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create remote access vpn"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create remote access vpn"); } } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java index 3dc334d0e2a..327f35b6688 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java @@ -94,12 +94,12 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { this.setEntityId(conn.getId()); this.setEntityUuid(conn.getUuid()); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create site to site vpn connection"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create site to site vpn connection"); } } catch (NetworkRuleConflictException e) { s_logger.info("Network rule conflict: " + e.getMessage()); s_logger.trace("Network Rule Conflict: ", e); - throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); + throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } } @@ -112,11 +112,11 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create site to site vpn connection"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create site to site vpn connection"); } } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java index bde98b0b44b..a14a5ec820c 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -160,7 +161,7 @@ public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create customer VPN gateway"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create customer VPN gateway"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java index 4b405541a90..2d2150b89b4 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.VpcResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -86,7 +87,7 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create VPN gateway"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPN gateway"); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java index 23a7793ef88..06521026bcb 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java @@ -86,11 +86,11 @@ public class DeleteVpnConnectionCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete site to site VPN connection"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete site to site VPN connection"); } } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java index 181ee3bbc68..854bb9b6ebf 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java @@ -84,7 +84,7 @@ public class DeleteVpnCustomerGatewayCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete customer VPN gateway"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete customer VPN gateway"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java index 9ac27d07664..6c89f7c9b93 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java @@ -85,7 +85,7 @@ public class DeleteVpnGatewayCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete customer VPN gateway"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete customer VPN gateway"); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java index bdad7e31dd9..11ca651f6a2 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.vpn; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -110,11 +111,11 @@ public class RemoveVpnUserCmd extends BaseAsyncCmd { Account owner = _accountService.getAccount(getEntityOwnerId()); boolean result = _ravService.removeVpnUser(owner.getId(), userName, UserContext.current().getCaller()); if (!result) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to remove vpn user"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove vpn user"); } if (!_ravService.applyVpnUsers(owner.getId(), userName)) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to apply vpn user removal"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to apply vpn user removal"); } SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java index ed28ea5610f..14e2f8cd853 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java @@ -104,11 +104,11 @@ public class ResetVpnConnectionCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to reset site to site VPN connection"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset site to site VPN connection"); } } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java index 7564129c38f..27b656d49da 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java @@ -155,7 +155,7 @@ public class UpdateVpnCustomerGatewayCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update customer VPN gateway"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update customer VPN gateway"); } } } diff --git a/plugins/api/discovery/src/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java b/plugins/api/discovery/src/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java index bad7ca7b5f6..18c3976f365 100644 --- a/plugins/api/discovery/src/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java +++ b/plugins/api/discovery/src/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java @@ -20,6 +20,7 @@ import com.cloud.user.User; import com.cloud.user.UserContext; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.PlugService; @@ -48,7 +49,7 @@ public class ListApisCmd extends BaseCmd { User user = UserContext.current().getCallerUser(); ListResponse response = (ListResponse) _apiDiscoveryService.listApis(user, name); if (response == null) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Api Discovery plugin was unable to find an api by that name or process any apis"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Api Discovery plugin was unable to find an api by that name or process any apis"); } response.setResponseName(getCommandName()); this.setResponseObject(response); diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/AssociateLunCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/AssociateLunCmd.java index c87c9242010..671b9f49174 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/AssociateLunCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/AssociateLunCmd.java @@ -21,6 +21,7 @@ import java.rmi.ServerException; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -39,27 +40,27 @@ public class AssociateLunCmd extends BaseCmd { ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required = true, description="LUN name.") private String lunName; - + @Parameter(name=ApiConstants.IQN, type=CommandType.STRING, required = true, description="Guest IQN to which the LUN associate.") private String guestIqn; - - + + /////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - - + + public String getLunName() { return lunName; } - + public String getGuestIQN() { return guestIqn; } - + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -68,12 +69,12 @@ public class AssociateLunCmd extends BaseCmd { public String getCommandName() { return s_name; } - + @Override public void execute(){ ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); NetappManager netappMgr = locator.getManager(NetappManager.class); - + try { AssociateLunCmdResponse response = new AssociateLunCmdResponse(); String returnVals[] = null; @@ -85,9 +86,9 @@ public class AssociateLunCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (ServerException e) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString()); } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString()); } } @@ -96,5 +97,5 @@ public class AssociateLunCmd extends BaseCmd { // TODO Auto-generated method stub return 0; } - + } diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateLunCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateLunCmd.java index 8c89730b978..fde0dc337f1 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateLunCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateLunCmd.java @@ -21,6 +21,7 @@ import java.rmi.ServerException; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -39,21 +40,21 @@ import com.cloud.utils.component.ComponentLocator; public class CreateLunCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(CreateLunCmd.class.getName()); private static final String s_name = "createlunresponse"; - + ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required = true, description="pool name.") private String poolName; - + @Parameter(name=ApiConstants.SIZE, type=CommandType.LONG, required = true, description="LUN size.") private long size; - + public String getPoolName() { return poolName; } - + public long getLunSize() { return size; } @@ -64,7 +65,7 @@ public class CreateLunCmd extends BaseCmd { ConcurrentOperationException, ResourceAllocationException { ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); NetappManager netappMgr = locator.getManager(NetappManager.class); - + try { CreateLunCmdResponse response = new CreateLunCmdResponse(); String returnVals[] = null; @@ -76,11 +77,11 @@ public class CreateLunCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (ServerException e) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString()); } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString()); } - + } @Override @@ -94,5 +95,5 @@ public class CreateLunCmd extends BaseCmd { // TODO Auto-generated method stub return 0; } - + } diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumeOnFilerCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumeOnFilerCmd.java index a2d4b96e6dd..5ca187d84f1 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumeOnFilerCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumeOnFilerCmd.java @@ -20,6 +20,7 @@ import java.net.UnknownHostException; import java.rmi.ServerException; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -40,64 +41,64 @@ public class CreateVolumeOnFilerCmd extends BaseCmd { @Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, required = true, description="ip address.") private String ipAddress; - + @Parameter(name=ApiConstants.AGGREGATE_NAME, type=CommandType.STRING, required = true, description="aggregate name.") private String aggrName; @Parameter(name=ApiConstants.POOL_NAME, type=CommandType.STRING, required = true, description="pool name.") private String poolName; - + @Parameter(name=ApiConstants.VOLUME_NAME, type=CommandType.STRING, required = true, description="volume name.") private String volName; - + @Parameter(name=ApiConstants.SIZE, type=CommandType.INTEGER, required = true, description="volume size.") private Integer volSize; - + @Parameter(name=ApiConstants.SNAPSHOT_POLICY, type=CommandType.STRING, required = false, description="snapshot policy.") private String snapshotPolicy; - + @Parameter(name=ApiConstants.SNAPSHOT_RESERVATION, type=CommandType.INTEGER, required = false, description="snapshot reservation.") private Integer snapshotReservation; - + @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="user name.") private String userName; - + @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="password.") private String password; - + public String getIpAddress() { return ipAddress; } - + public String getAggrName() { return aggrName; } - + public String getPoolName() { return poolName; } - + public String volName() { return volName; } - + public Integer getVolSize() { return volSize; } - + public String getSnapshotPolicy() { return snapshotPolicy; } - + public Integer getSnapshotReservation() { return snapshotReservation; } - + public String getUserName() { return userName; } - + public String getPassword() { return password; } @@ -109,26 +110,26 @@ public class CreateVolumeOnFilerCmd extends BaseCmd { //param checks if(snapshotReservation != null && (snapshotReservation<0 || snapshotReservation>100)) throw new InvalidParameterValueException("Invalid snapshot reservation"); - + ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); NetappManager netappMgr = locator.getManager(NetappManager.class); - + StringBuilder s = new StringBuilder(getVolSize().toString()); s.append("g"); - + try { netappMgr.createVolumeOnFiler(ipAddress, aggrName, poolName, volName, s.toString(), snapshotPolicy, snapshotReservation, userName, password); CreateVolumeOnFilerCmdResponse response = new CreateVolumeOnFilerCmdResponse(); response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (ServerException e) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString()); } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString()); } catch (UnknownHostException e) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString()); } - + } @Override @@ -142,5 +143,5 @@ public class CreateVolumeOnFilerCmd extends BaseCmd { // TODO Auto-generated method stub return 0; } - + } diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumePoolCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumePoolCmd.java index 9e38c5fc097..107f6b0583f 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumePoolCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumePoolCmd.java @@ -19,6 +19,7 @@ package com.cloud.api.commands.netapp; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -42,11 +43,11 @@ public class CreateVolumePoolCmd extends BaseCmd { private String poolName; @Parameter(name=ApiConstants.ALGORITHM, type=CommandType.STRING, required = true, description="algorithm.") private String algorithm; - + public String getPoolName() { return poolName; } - + public String getAlgorithm() { return algorithm; } @@ -57,16 +58,16 @@ public class CreateVolumePoolCmd extends BaseCmd { ConcurrentOperationException, ResourceAllocationException { ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); NetappManager netappMgr = locator.getManager(NetappManager.class); - + try { CreateVolumePoolCmdResponse response = new CreateVolumePoolCmdResponse(); netappMgr.createPool(getPoolName(), getAlgorithm()); response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString()); } - + } @Override @@ -80,5 +81,5 @@ public class CreateVolumePoolCmd extends BaseCmd { // TODO Auto-generated method stub return 0; } - + } diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DeleteVolumePoolCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DeleteVolumePoolCmd.java index 1105ea53e9d..a70b6d4a0da 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DeleteVolumePoolCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DeleteVolumePoolCmd.java @@ -20,6 +20,7 @@ package com.cloud.api.commands.netapp; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -39,7 +40,7 @@ import com.cloud.utils.component.ComponentLocator; public class DeleteVolumePoolCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(DeleteVolumePoolCmd.class.getName()); private static final String s_name = "deletepoolresponse"; - + @Parameter(name=ApiConstants.POOL_NAME, type=CommandType.STRING, required = true, description="pool name.") private String poolName; @@ -55,9 +56,9 @@ public class DeleteVolumePoolCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString()); } catch (ResourceInUseException e) { - throw new ServerApiException(BaseCmd.RESOURCE_IN_USE_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, e.toString()); } } @@ -72,5 +73,5 @@ public class DeleteVolumePoolCmd extends BaseCmd { // TODO Auto-generated method stub return 0; } - + } diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyLunCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyLunCmd.java index c5f7b117f5b..1b3e6bc84a8 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyLunCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyLunCmd.java @@ -21,6 +21,7 @@ import java.rmi.ServerException; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -37,7 +38,7 @@ import com.cloud.utils.component.ComponentLocator; @APICommand(name = "destroyLunOnFiler", description="Destroy a LUN", responseObject = DeleteLUNCmdResponse.class) public class DestroyLunCmd extends BaseCmd { - + public static final Logger s_logger = Logger.getLogger(DestroyLunCmd.class.getName()); private static final String s_name = "destroylunresponse"; @@ -56,9 +57,9 @@ public class DestroyLunCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString()); } catch (ServerException e) { - throw new ServerApiException(BaseCmd.RESOURCE_IN_USE_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, e.toString()); } } @@ -73,5 +74,5 @@ public class DestroyLunCmd extends BaseCmd { // TODO Auto-generated method stub return 0; } - + } diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyVolumeOnFilerCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyVolumeOnFilerCmd.java index 4ddc0c9f6d0..21e10b0148f 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyVolumeOnFilerCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyVolumeOnFilerCmd.java @@ -37,17 +37,17 @@ import com.cloud.utils.component.ComponentLocator; public class DestroyVolumeOnFilerCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(DestroyVolumeOnFilerCmd.class.getName()); private static final String s_name = "destroyvolumeresponse"; - + @Parameter(name=ApiConstants.AGGREGATE_NAME, type=CommandType.STRING, required = true, description="aggregate name.") private String aggrName; - + @Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, required = true, description="ip address.") private String ipAddr; - + @Parameter(name=ApiConstants.VOLUME_NAME, type=CommandType.STRING, required = true, description="volume name.") private String volumeName; - - + + @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, @@ -60,13 +60,13 @@ public class DestroyVolumeOnFilerCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString()); } catch (ResourceInUseException e) { - throw new ServerApiException(BaseCmd.RESOURCE_IN_USE_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, e.toString()); } catch (ServerException e) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString()); } - + } @Override @@ -80,5 +80,5 @@ public class DestroyVolumeOnFilerCmd extends BaseCmd { // TODO Auto-generated method stub return 0; } - + } \ No newline at end of file diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DissociateLunCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DissociateLunCmd.java index 0a6c1a70ef1..f373c65bedd 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DissociateLunCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DissociateLunCmd.java @@ -39,10 +39,10 @@ public class DissociateLunCmd extends BaseCmd { @Parameter(name=ApiConstants.PATH, type=CommandType.STRING, required = true, description="LUN path.") private String path; - + @Parameter(name=ApiConstants.IQN, type=CommandType.STRING, required = true, description="Guest IQN.") private String guestIQN; - + @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, @@ -55,9 +55,9 @@ public class DissociateLunCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString()); } catch (ServerException e) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString()); } } diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListLunsCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListLunsCmd.java index 630b14994e7..61b81db90c8 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListLunsCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListLunsCmd.java @@ -22,6 +22,7 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -39,7 +40,7 @@ import com.cloud.server.api.response.netapp.ListLunsCmdResponse; import com.cloud.utils.component.ComponentLocator; @APICommand(name = "listLunsOnFiler", description="List LUN", responseObject = ListLunsCmdResponse.class) -public class ListLunsCmd extends BaseCmd +public class ListLunsCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(ListLunsCmd.class.getName()); private static final String s_name = "listlunresponse"; @@ -70,8 +71,8 @@ public class ListLunsCmd extends BaseCmd listResponse.setResponseName(getCommandName()); this.setResponseObject(listResponse); } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString()); - } + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString()); + } } @Override diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumePoolsCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumePoolsCmd.java index d77f4fad849..882cf1b2b44 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumePoolsCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumePoolsCmd.java @@ -21,6 +21,7 @@ import java.util.List; import org.apache.log4j.Logger; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ServerApiException; @@ -64,9 +65,9 @@ public class ListVolumePoolsCmd extends BaseCmd { listResponse.setResponseName(getCommandName()); this.setResponseObject(listResponse); } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString()); - } - + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.toString()); + } + } @Override diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumesOnFilerCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumesOnFilerCmd.java index 66a96f3a221..3cc98f43d90 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumesOnFilerCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumesOnFilerCmd.java @@ -39,7 +39,7 @@ import com.cloud.utils.component.ComponentLocator; public class ListVolumesOnFilerCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(ListVolumesOnFilerCmd.class.getName()); private static final String s_name = "listvolumesresponse"; - + @Parameter(name=ApiConstants.POOL_NAME, type=CommandType.STRING, required = true, description="pool name.") private String poolName; @@ -49,7 +49,7 @@ public class ListVolumesOnFilerCmd extends BaseCmd { ConcurrentOperationException, ResourceAllocationException { ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); NetappManager netappMgr = locator.getManager(NetappManager.class); - + try { List volumes = netappMgr.listVolumesOnFiler(poolName); ListResponse listResponse = new ListResponse(); @@ -71,9 +71,9 @@ public class ListVolumesOnFilerCmd extends BaseCmd { listResponse.setResponseName(getCommandName()); this.setResponseObject(listResponse); } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.toString()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString()); } - + } @Override diff --git a/plugins/hypervisors/simulator/src/com/cloud/api/commands/ConfigureSimulator.java b/plugins/hypervisors/simulator/src/com/cloud/api/commands/ConfigureSimulator.java index df81249538d..e6afcc9f4b4 100755 --- a/plugins/hypervisors/simulator/src/com/cloud/api/commands/ConfigureSimulator.java +++ b/plugins/hypervisors/simulator/src/com/cloud/api/commands/ConfigureSimulator.java @@ -20,6 +20,7 @@ import org.apache.log4j.Logger; import com.cloud.agent.manager.SimulatorManager; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -62,7 +63,7 @@ public class ConfigureSimulator extends BaseCmd { SimulatorManager _simMgr = locator.getManager(SimulatorManager.class); boolean result = _simMgr.configureSimulator(zoneId, podId, clusterId, hostId, command, values); if (!result) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to configure simulator"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure simulator"); } SuccessResponse response = new SuccessResponse(getCommandName()); diff --git a/plugins/hypervisors/vmware/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java b/plugins/hypervisors/vmware/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java index 3e45ce2a084..1496f295ccb 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java +++ b/plugins/hypervisors/vmware/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java @@ -20,6 +20,7 @@ package com.cloud.api.commands; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -70,7 +71,7 @@ public class DeleteCiscoNexusVSMCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to delete Cisco Nexus VSM device"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Cisco Nexus VSM device"); } } @@ -83,7 +84,7 @@ public class DeleteCiscoNexusVSMCmd extends BaseAsyncCmd { public long getEntityOwnerId() { return Account.ACCOUNT_ID_SYSTEM; } - + @Override public String getEventType() { return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DELETE; diff --git a/plugins/hypervisors/vmware/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java b/plugins/hypervisors/vmware/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java index 9a7f6ada97c..67a74081292 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java +++ b/plugins/hypervisors/vmware/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java @@ -20,6 +20,7 @@ package com.cloud.api.commands; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -70,7 +71,7 @@ public class DisableCiscoNexusVSMCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to disable Cisco Nexus VSM device"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to disable Cisco Nexus VSM device"); } } @@ -92,5 +93,5 @@ public class DisableCiscoNexusVSMCmd extends BaseAsyncCmd { @Override public String getEventType() { return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DISABLE; - } + } } diff --git a/plugins/hypervisors/vmware/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java b/plugins/hypervisors/vmware/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java index 5dc67212fd3..5064c9faabc 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java +++ b/plugins/hypervisors/vmware/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java @@ -66,7 +66,7 @@ public class EnableCiscoNexusVSMCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to enable Cisco Nexus VSM device"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable Cisco Nexus VSM device"); } } diff --git a/plugins/hypervisors/vmware/src/com/cloud/api/commands/ListCiscoNexusVSMsCmd.java b/plugins/hypervisors/vmware/src/com/cloud/api/commands/ListCiscoNexusVSMsCmd.java index ee6a01bdb8a..1ac00f9c6d8 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/api/commands/ListCiscoNexusVSMsCmd.java +++ b/plugins/hypervisors/vmware/src/com/cloud/api/commands/ListCiscoNexusVSMsCmd.java @@ -21,6 +21,7 @@ import org.apache.cloudstack.api.response.ClusterResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -44,7 +45,7 @@ public class ListCiscoNexusVSMsCmd extends BaseListCmd { /** * This command returns a list of all the VSMs configured in the management server. - * If a clusterId is specified, it will return a list containing only that VSM + * If a clusterId is specified, it will return a list containing only that VSM * that is associated with that cluster. If a zone is specified, it will pull * up all the clusters of type vmware in that zone, and prepare a list of VSMs * associated with those clusters. @@ -60,7 +61,7 @@ public class ListCiscoNexusVSMsCmd extends BaseListCmd { @Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.UUID, entityType = ClusterResponse.class, required = false, description="Id of the CloudStack cluster in which the Cisco Nexus 1000v VSM appliance.") private long clusterId; - + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class, required = false, description="Id of the CloudStack cluster in which the Cisco Nexus 1000v VSM appliance.") private long zoneId; @@ -68,11 +69,11 @@ public class ListCiscoNexusVSMsCmd extends BaseListCmd { ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - + public long getClusterId() { return clusterId; } - + public long getZoneId() { return zoneId; } @@ -87,7 +88,7 @@ public class ListCiscoNexusVSMsCmd extends BaseListCmd { @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { List vsmDeviceList = _ciscoNexusVSMService.getCiscoNexusVSMs(this); - + if (vsmDeviceList.size() > 0) { ListResponse response = new ListResponse(); List vsmResponses = new ArrayList(); @@ -101,10 +102,10 @@ public class ListCiscoNexusVSMsCmd extends BaseListCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseListCmd.INTERNAL_ERROR, "No VSM found."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "No VSM found."); } } - + @Override public String getCommandName() { return s_name; diff --git a/plugins/network-elements/f5/src/com/cloud/api/commands/AddExternalLoadBalancerCmd.java b/plugins/network-elements/f5/src/com/cloud/api/commands/AddExternalLoadBalancerCmd.java index 69a21fc184c..29a2c0bee68 100644 --- a/plugins/network-elements/f5/src/com/cloud/api/commands/AddExternalLoadBalancerCmd.java +++ b/plugins/network-elements/f5/src/com/cloud/api/commands/AddExternalLoadBalancerCmd.java @@ -21,6 +21,7 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -38,11 +39,11 @@ import com.cloud.utils.exception.CloudRuntimeException; public class AddExternalLoadBalancerCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(AddExternalLoadBalancerCmd.class.getName()); private static final String s_name = "addexternalloadbalancerresponse"; - + ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class, required = true, description="Zone in which to add the external load balancer appliance.") private Long zoneId; @@ -59,19 +60,19 @@ public class AddExternalLoadBalancerCmd extends BaseCmd { /////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - + public Long getZoneId() { return zoneId; } - + public String getUrl() { return url; } - + public String getUsername() { return username; } - + public String getPassword() { return password; } @@ -102,9 +103,9 @@ public class AddExternalLoadBalancerCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException ipve) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, ipve.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage()); } catch (CloudRuntimeException cre) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, cre.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage()); } } } diff --git a/plugins/network-elements/f5/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java b/plugins/network-elements/f5/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java index a5616e0ee73..839f60f71d6 100644 --- a/plugins/network-elements/f5/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java +++ b/plugins/network-elements/f5/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java @@ -54,7 +54,7 @@ public class AddF5LoadBalancerCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Credentials to reach F5 BigIP load balancer device") private String username; - + @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to reach F5 BigIP load balancer device") private String password; @@ -99,12 +99,12 @@ public class AddF5LoadBalancerCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to add F5 Big IP load balancer due to internal error."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add F5 Big IP load balancer due to internal error."); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } @@ -117,7 +117,7 @@ public class AddF5LoadBalancerCmd extends BaseAsyncCmd { public String getEventType() { return EventTypes.EVENT_EXTERNAL_LB_DEVICE_ADD; } - + @Override public String getCommandName() { return s_name; diff --git a/plugins/network-elements/f5/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java b/plugins/network-elements/f5/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java index e796b57cc41..cc7d1be9c78 100644 --- a/plugins/network-elements/f5/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java +++ b/plugins/network-elements/f5/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java @@ -77,12 +77,12 @@ public class ConfigureF5LoadBalancerCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to configure F5 load balancer due to internal error."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure F5 load balancer due to internal error."); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteExternalLoadBalancerCmd.java b/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteExternalLoadBalancerCmd.java index d3015712596..29eaa0c781b 100644 --- a/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteExternalLoadBalancerCmd.java +++ b/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteExternalLoadBalancerCmd.java @@ -32,19 +32,19 @@ import com.cloud.user.Account; public class DeleteExternalLoadBalancerCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(DeleteExternalLoadBalancerCmd.class.getName()); private static final String s_name = "deleteexternalloadbalancerresponse"; - + ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = HostResponse.class, required = true, description="Id of the external loadbalancer appliance.") private Long id; - + /////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - + public Long getId() { return id; } @@ -60,12 +60,12 @@ public class DeleteExternalLoadBalancerCmd extends BaseCmd { public String getCommandName() { return s_name; } - + @Override public long getEntityOwnerId() { return Account.ACCOUNT_ID_SYSTEM; } - + @Override public void execute(){ try { @@ -75,10 +75,10 @@ public class DeleteExternalLoadBalancerCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete external load balancer."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete external load balancer."); } } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, "Failed to delete external load balancer."); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Failed to delete external load balancer."); } } } diff --git a/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java b/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java index 8b53d70f76d..c1ab22ddc30 100644 --- a/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java +++ b/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java @@ -22,6 +22,7 @@ import org.apache.log4j.Logger; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -74,12 +75,12 @@ public class DeleteF5LoadBalancerCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete F5 load balancer."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete F5 load balancer."); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancerNetworksCmd.java b/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancerNetworksCmd.java index bf1164b4d05..1d276ce10e7 100644 --- a/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancerNetworksCmd.java +++ b/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancerNetworksCmd.java @@ -23,6 +23,7 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.APICommand; @@ -86,9 +87,9 @@ public class ListF5LoadBalancerNetworksCmd extends BaseListCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancersCmd.java b/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancersCmd.java index c03d55abc0a..deaa2750d25 100644 --- a/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancersCmd.java +++ b/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancersCmd.java @@ -88,9 +88,9 @@ public class ListF5LoadBalancersCmd extends BaseListCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddExternalFirewallCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddExternalFirewallCmd.java index cda27fb8960..deaa6128b93 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddExternalFirewallCmd.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddExternalFirewallCmd.java @@ -11,7 +11,7 @@ // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.api.commands; @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -34,30 +35,30 @@ import com.cloud.utils.exception.CloudRuntimeException; @APICommand(name = "addExternalFirewall", description="Adds an external firewall appliance", responseObject = ExternalFirewallResponse.class) public class AddExternalFirewallCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddExternalFirewallCmd.class.getName()); - private static final String s_name = "addexternalfirewallresponse"; - + public static final Logger s_logger = Logger.getLogger(AddExternalFirewallCmd.class.getName()); + private static final String s_name = "addexternalfirewallresponse"; + ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class, required = true, description="Zone in which to add the external firewall appliance.") private Long zoneId; @Parameter(name=ApiConstants.URL, type=CommandType.STRING, required = true, description="URL of the external firewall appliance.") - private String url; - + private String url; + @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Username of the external firewall appliance.") - private String username; - + private String username; + @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Password of the external firewall appliance.") private String password; - + /////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - + public Long getZoneId() { return zoneId; } @@ -65,15 +66,15 @@ public class AddExternalFirewallCmd extends BaseCmd { public String getUrl() { return url; } - + public String getUsername() { return username; } - + public String getPassword() { return password; } - + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// @@ -85,12 +86,12 @@ public class AddExternalFirewallCmd extends BaseCmd { public String getCommandName() { return s_name; } - + @Override public long getEntityOwnerId() { return Account.ACCOUNT_ID_SYSTEM; } - + @SuppressWarnings("deprecation") @Override public void execute(){ @@ -101,9 +102,9 @@ public class AddExternalFirewallCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException ipve) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, ipve.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage()); } catch (CloudRuntimeException cre) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, cre.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage()); } } } diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddSrxFirewallCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddSrxFirewallCmd.java index a2ad4e5ce2b..9ed6814035e 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddSrxFirewallCmd.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddSrxFirewallCmd.java @@ -11,7 +11,7 @@ // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.api.commands; @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.PhysicalNetworkResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -57,7 +58,7 @@ public class AddSrxFirewallCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Credentials to reach SRX firewall device") private String username; - + @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to reach SRX firewall device") private String password; @@ -102,12 +103,12 @@ public class AddSrxFirewallCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to add SRX firewall due to internal error."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add SRX firewall due to internal error."); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } @@ -120,7 +121,7 @@ public class AddSrxFirewallCmd extends BaseAsyncCmd { public String getEventType() { return EventTypes.EVENT_EXTERNAL_FIREWALL_DEVICE_ADD; } - + @Override public String getCommandName() { return s_name; diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java index 482fcc8c0c7..c9ea7cbe374 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java @@ -11,7 +11,7 @@ // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.api.commands; @@ -19,6 +19,7 @@ package com.cloud.api.commands; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -81,12 +82,12 @@ public class ConfigureSrxFirewallCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to configure SRX firewall device due to internal error."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure SRX firewall device due to internal error."); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteExternalFirewallCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteExternalFirewallCmd.java index 5cdc9e3c92c..77597898ac0 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteExternalFirewallCmd.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteExternalFirewallCmd.java @@ -11,7 +11,7 @@ // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.api.commands; @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.HostResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -32,9 +33,9 @@ import com.cloud.user.Account; @APICommand(name = "deleteExternalFirewall", description="Deletes an external firewall appliance.", responseObject = SuccessResponse.class) public class DeleteExternalFirewallCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteExternalFirewallCmd.class.getName()); - private static final String s_name = "deleteexternalfirewallresponse"; - + public static final Logger s_logger = Logger.getLogger(DeleteExternalFirewallCmd.class.getName()); + private static final String s_name = "deleteexternalfirewallresponse"; + ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// @@ -42,15 +43,15 @@ public class DeleteExternalFirewallCmd extends BaseCmd { @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = HostResponse.class, required = true, description="Id of the external firewall appliance.") private Long id; - + /////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - + public Long getId() { return id; } - + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -61,7 +62,7 @@ public class DeleteExternalFirewallCmd extends BaseCmd { public String getCommandName() { return s_name; } - + @Override public long getEntityOwnerId() { return Account.ACCOUNT_ID_SYSTEM; @@ -77,10 +78,10 @@ public class DeleteExternalFirewallCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete external firewall."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete external firewall."); } } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, "Failed to delete external firewall."); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Failed to delete external firewall."); } } } diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java index 1dc792a723a..e45fe3180e8 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java @@ -11,7 +11,7 @@ // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.api.commands; @@ -19,6 +19,7 @@ package com.cloud.api.commands; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -72,12 +73,12 @@ public class DeleteSrxFirewallCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete SRX firewall device"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete SRX firewall device"); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallNetworksCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallNetworksCmd.java index 9c2b3962a6f..03ae962bff8 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallNetworksCmd.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallNetworksCmd.java @@ -11,7 +11,7 @@ // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.api.commands; @@ -80,9 +80,9 @@ public class ListSrxFirewallNetworksCmd extends BaseListCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallsCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallsCmd.java index 6508cc83c7d..5242316a574 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallsCmd.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallsCmd.java @@ -11,7 +11,7 @@ // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.api.commands; @@ -88,9 +88,9 @@ public class ListSrxFirewallsCmd extends BaseListCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java index 9d902975723..79c657f5210 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java +++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java @@ -51,7 +51,7 @@ public class AddNetscalerLoadBalancerCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Credentials to reach netscaler load balancer device") private String username; - + @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to reach netscaler load balancer device") private String password; @@ -96,12 +96,12 @@ public class AddNetscalerLoadBalancerCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to add netscaler load balancer due to internal error."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add netscaler load balancer due to internal error."); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } @@ -114,7 +114,7 @@ public class AddNetscalerLoadBalancerCmd extends BaseAsyncCmd { public String getEventType() { return EventTypes.EVENT_EXTERNAL_LB_DEVICE_ADD; } - + @Override public String getCommandName() { return s_name; diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java index e0ec73ad501..33fe7a2e504 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java +++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java @@ -101,12 +101,12 @@ public class ConfigureNetscalerLoadBalancerCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to configure netscaler load balancer due to internal error."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure netscaler load balancer due to internal error."); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/DeleteNetscalerLoadBalancerCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/DeleteNetscalerLoadBalancerCmd.java index ec7faab39d4..5f62b802e81 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/DeleteNetscalerLoadBalancerCmd.java +++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/DeleteNetscalerLoadBalancerCmd.java @@ -18,6 +18,7 @@ package com.cloud.api.commands; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -72,12 +73,12 @@ public class DeleteNetscalerLoadBalancerCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete netscaler load balancer."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete netscaler load balancer."); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancerNetworksCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancerNetworksCmd.java index 52476df8316..ec94c6e7683 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancerNetworksCmd.java +++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancerNetworksCmd.java @@ -20,6 +20,7 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.APICommand; @@ -83,9 +84,9 @@ public class ListNetscalerLoadBalancerNetworksCmd extends BaseListCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancersCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancersCmd.java index bf679fa51c1..8886218b057 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancersCmd.java +++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancersCmd.java @@ -21,6 +21,7 @@ import org.apache.cloudstack.api.response.PhysicalNetworkResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.APICommand; @@ -91,9 +92,9 @@ public class ListNetscalerLoadBalancersCmd extends BaseListCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java index 1734ce2ff3d..3bd39b80c9d 100644 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java +++ b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java @@ -38,7 +38,7 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd { private static final Logger s_logger = Logger.getLogger(AddNiciraNvpDeviceCmd.class.getName()); private static final String s_name = "addniciranvpdeviceresponse"; @PlugService NiciraNvpElementService _niciraNvpElementService; - + ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// @@ -52,16 +52,16 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Credentials to access the Nicira Controller API") private String username; - + @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to access the Nicira Controller API") private String password; - + @Parameter(name=ApiConstants.NICIRA_NVP_TRANSPORT_ZONE_UUID, type=CommandType.STRING, required = true, description="The Transportzone UUID configured on the Nicira Controller") private String transportzoneuuid; - + @Parameter(name=ApiConstants.NICIRA_NVP_GATEWAYSERVICE_UUID, type=CommandType.STRING, required = false, description="The L3 Gateway Service UUID configured on the Nicira Controller") private String l3gatewayserviceuuid; - + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -81,11 +81,11 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd { public String getPassword() { return password; } - + public String getTransportzoneUuid() { return transportzoneuuid; } - + public String getL3GatewayServiceUuid() { return l3gatewayserviceuuid; } @@ -104,15 +104,15 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to add Nicira NVP device due to internal error."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Nicira NVP device due to internal error."); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } - + @Override public String getCommandName() { return s_name; diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/DeleteNiciraNvpDeviceCmd.java b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/DeleteNiciraNvpDeviceCmd.java index 12544410599..9a10c2879d3 100644 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/DeleteNiciraNvpDeviceCmd.java +++ b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/DeleteNiciraNvpDeviceCmd.java @@ -20,6 +20,7 @@ import com.cloud.api.response.NiciraNvpDeviceResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; @@ -72,12 +73,12 @@ public class DeleteNiciraNvpDeviceCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete Nicira device."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Nicira device."); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDeviceNetworksCmd.java b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDeviceNetworksCmd.java index bea417d3687..70973c0a5a5 100644 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDeviceNetworksCmd.java +++ b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDeviceNetworksCmd.java @@ -23,6 +23,7 @@ import com.cloud.api.response.NiciraNvpDeviceResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.APICommand; @@ -85,9 +86,9 @@ public class ListNiciraNvpDeviceNetworksCmd extends BaseListCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDevicesCmd.java b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDevicesCmd.java index 04aab2a296a..0d2ca5a2335 100644 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDevicesCmd.java +++ b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDevicesCmd.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.Parameter; @@ -92,9 +93,9 @@ public class ListNiciraNvpDevicesCmd extends BaseListCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } } @@ -102,5 +103,5 @@ public class ListNiciraNvpDevicesCmd extends BaseListCmd { public String getCommandName() { return s_name; } - + } diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index 55d7f429ca1..04b46e5a579 100755 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -105,46 +105,13 @@ public class ApiDispatcher { _daoNameMap.put("com.cloud.template.VirtualMachineTemplate", VMTemplateDao.class); } - public void dispatchCreateCmd(BaseAsyncCreateCmd cmd, Map params) { - processParameters(cmd, params); + public void dispatchCreateCmd(BaseAsyncCreateCmd cmd, Map params) throws Exception { + processParameters(cmd, params); + + UserContext ctx = UserContext.current(); + ctx.setAccountId(cmd.getEntityOwnerId()); + cmd.create(); - try { - UserContext ctx = UserContext.current(); - ctx.setAccountId(cmd.getEntityOwnerId()); - cmd.create(); - } catch (Throwable t) { - if (t instanceof InvalidParameterValueException || t instanceof IllegalArgumentException) { - s_logger.info(t.getMessage()); - throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage()); - } else if (t instanceof PermissionDeniedException) { - s_logger.info("PermissionDenied: " + t.getMessage()); - throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage()); - } else if (t instanceof AccountLimitException) { - s_logger.info(t.getMessage()); - throw new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage()); - } else if (t instanceof InsufficientCapacityException) { - s_logger.info(t.getMessage()); - throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage()); - } else if (t instanceof ResourceAllocationException) { - s_logger.info(t.getMessage()); - throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage()); - } else if (t instanceof ResourceUnavailableException) { - s_logger.warn("Exception: ", t); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage()); - } else if (t instanceof AsyncCommandQueued) { - throw (AsyncCommandQueued) t; - } else if (t instanceof ServerApiException) { - s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription()); - throw (ServerApiException) t; - } else { - s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t); - if (UserContext.current().getCaller().getType() == Account.ACCOUNT_TYPE_ADMIN) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage()); - } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE); - } - } - } } private void doAccessChecks(BaseCmd cmd, List entitiesToAccess) { @@ -170,164 +137,36 @@ public class ApiDispatcher { } } - public void dispatch(BaseCmd cmd, Map params) { - try { - processParameters(cmd, params); - UserContext ctx = UserContext.current(); - ctx.setAccountId(cmd.getEntityOwnerId()); - if (cmd instanceof BaseAsyncCmd) { + public void dispatch(BaseCmd cmd, Map params) throws Exception { + processParameters(cmd, params); + UserContext ctx = UserContext.current(); + ctx.setAccountId(cmd.getEntityOwnerId()); + if (cmd instanceof BaseAsyncCmd) { - BaseAsyncCmd asyncCmd = (BaseAsyncCmd) cmd; - String startEventId = params.get("ctxStartEventId"); - ctx.setStartEventId(Long.valueOf(startEventId)); + BaseAsyncCmd asyncCmd = (BaseAsyncCmd) cmd; + String startEventId = params.get("ctxStartEventId"); + ctx.setStartEventId(Long.valueOf(startEventId)); - // Synchronise job on the object if needed - if (asyncCmd.getJob() != null && asyncCmd.getSyncObjId() != null && asyncCmd.getSyncObjType() != null) { - Long queueSizeLimit = null; - if (asyncCmd.getSyncObjType() != null && asyncCmd.getSyncObjType().equalsIgnoreCase(BaseAsyncCmd.snapshotHostSyncObject)) { - queueSizeLimit = _createSnapshotQueueSizeLimit; - } else { - queueSizeLimit = 1L; - } + // Synchronise job on the object if needed + if (asyncCmd.getJob() != null && asyncCmd.getSyncObjId() != null && asyncCmd.getSyncObjType() != null) { + Long queueSizeLimit = null; + if (asyncCmd.getSyncObjType() != null && asyncCmd.getSyncObjType().equalsIgnoreCase(BaseAsyncCmd.snapshotHostSyncObject)) { + queueSizeLimit = _createSnapshotQueueSizeLimit; + } else { + queueSizeLimit = 1L; + } - if (queueSizeLimit != null) { - _asyncMgr.syncAsyncJobExecution(asyncCmd.getJob(), asyncCmd.getSyncObjType(), - asyncCmd.getSyncObjId().longValue(), queueSizeLimit); - } else { - s_logger.trace("The queue size is unlimited, skipping the synchronizing"); - } - } - } - - cmd.execute(); - - } catch (Throwable t) { - if (t instanceof InvalidParameterValueException) { - // earlier, we'd log the db id as part of the log message, but now since we've pushed - // the id into a IdentityProxy object, we would need to dump that object alongwith the - // message. - InvalidParameterValueException ref = (InvalidParameterValueException) t; - ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage()); - // copy over the IdentityProxy information as well and throw the serverapiexception. - ArrayList idList = ref.getIdProxyList(); - if (idList != null) { - // Iterate through entire arraylist and copy over each proxy id. - for (int i = 0 ; i < idList.size(); i++) { - ex.addProxyObject(idList.get(i)); - s_logger.info(t.getMessage() + " uuid: " + idList.get(i)); - } + if (queueSizeLimit != null) { + _asyncMgr + .syncAsyncJobExecution(asyncCmd.getJob(), asyncCmd.getSyncObjType(), asyncCmd.getSyncObjId().longValue(), queueSizeLimit); } else { - s_logger.info(t.getMessage()); + s_logger.trace("The queue size is unlimited, skipping the synchronizing"); } - // Also copy over the cserror code. - ex.setCSErrorCode(ref.getCSErrorCode()); - throw ex; - } else if(t instanceof IllegalArgumentException) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage()); - } else if (t instanceof PermissionDeniedException) { - PermissionDeniedException ref = (PermissionDeniedException)t; - ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage()); - // copy over the IdentityProxy information as well and throw the serverapiexception. - ArrayList idList = ref.getIdProxyList(); - if (idList != null) { - // Iterate through entire arraylist and copy over each proxy id. - for (int i = 0 ; i < idList.size(); i++) { - ex.addProxyObject(idList.get(i)); - s_logger.info("PermissionDenied: " + t.getMessage() + "uuid: " + idList.get(i)); - } - } else { - s_logger.info("PermissionDenied: " + t.getMessage()); - } - // Also copy over the cserror code. - ex.setCSErrorCode(ref.getCSErrorCode()); - throw ex; - } else if (t instanceof AccountLimitException) { - AccountLimitException ref = (AccountLimitException)t; - ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage()); - // copy over the IdentityProxy information as well and throw the serverapiexception. - ArrayList idList = ref.getIdProxyList(); - if (idList != null) { - // Iterate through entire arraylist and copy over each proxy id. - for (int i = 0 ; i < idList.size(); i++) { - ex.addProxyObject(idList.get(i)); - s_logger.info(t.getMessage() + "uuid: " + idList.get(i)); - } - } else { - s_logger.info(t.getMessage()); - } - // Also copy over the cserror code. - ex.setCSErrorCode(ref.getCSErrorCode()); - throw ex; - } else if (t instanceof InsufficientCapacityException) { - InsufficientCapacityException ref = (InsufficientCapacityException)t; - ServerApiException ex = new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage()); - // copy over the IdentityProxy information as well and throw the serverapiexception. - ArrayList idList = ref.getIdProxyList(); - if (idList != null) { - // Iterate through entire arraylist and copy over each proxy id. - for (int i = 0 ; i < idList.size(); i++) { - ex.addProxyObject(idList.get(i)); - s_logger.info(t.getMessage() + "uuid: " + idList.get(i)); - } - } else { - s_logger.info(t.getMessage()); - } - // Also copy over the cserror code - ex.setCSErrorCode(ref.getCSErrorCode()); - throw ex; - } else if (t instanceof ResourceAllocationException) { - ResourceAllocationException ref = (ResourceAllocationException)t; - ServerApiException ex = new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage()); - // copy over the IdentityProxy information as well and throw the serverapiexception. - ArrayList idList = ref.getIdProxyList(); - if (idList != null) { - // Iterate through entire arraylist and copy over each proxy id. - for (int i = 0 ; i < idList.size(); i++) { - String id = idList.get(i); - ex.addProxyObject(id); - s_logger.warn("Exception: " + t.getMessage() + "uuid: " + id); - } - } else { - s_logger.warn("Exception: ", t); - } - // Also copy over the cserror code. - ex.setCSErrorCode(ref.getCSErrorCode()); - throw ex; - } else if (t instanceof ResourceUnavailableException) { - ResourceUnavailableException ref = (ResourceUnavailableException)t; - ServerApiException ex = new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage()); - // copy over the IdentityProxy information as well and throw the serverapiexception. - ArrayList idList = ref.getIdProxyList(); - if (idList != null) { - // Iterate through entire arraylist and copy over each proxy id. - for (int i = 0 ; i < idList.size(); i++) { - String id = idList.get(i); - ex.addProxyObject(id); - s_logger.warn("Exception: " + t.getMessage() + "uuid: " + id); - } - } else { - s_logger.warn("Exception: ", t); - } - // Also copy over the cserror code. - ex.setCSErrorCode(ref.getCSErrorCode()); - throw ex; - } else if (t instanceof AsyncCommandQueued) { - throw (AsyncCommandQueued) t; - } else if (t instanceof ServerApiException) { - s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription()); - throw (ServerApiException) t; - } else { - s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t); - ServerApiException ex; - if (UserContext.current().getCaller().getType() == Account.ACCOUNT_TYPE_ADMIN) { - ex = new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage()); - } else { - ex = new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE); - } - ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName())); - throw ex; } } + + cmd.execute(); + } @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -343,11 +182,11 @@ public class ApiDispatcher { } if ((unpackedParams.get(ApiConstants.PAGE) == null) && (pageSize != null && pageSize != BaseListCmd.PAGESIZE_UNLIMITED)) { - ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified"); + ServerApiException ex = new ServerApiException(ApiErrorCode.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified"); ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName())); throw ex; } else if (pageSize == null && (unpackedParams.get(ApiConstants.PAGE) != null)) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, "\"pagesize\" parameter is required when \"page\" is specified"); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "\"pagesize\" parameter is required when \"page\" is specified"); } } @@ -370,7 +209,7 @@ public class ApiDispatcher { Object paramObj = unpackedParams.get(parameterAnnotation.name()); if (paramObj == null) { if (parameterAnnotation.required()) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to missing parameter " + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to missing parameter " + parameterAnnotation.name()); } continue; @@ -383,23 +222,23 @@ public class ApiDispatcher { if (s_logger.isDebugEnabled()) { s_logger.debug("Unable to execute API command " + cmd.getCommandName() + " due to invalid value " + paramObj + " for parameter " + parameterAnnotation.name()); } - throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value " + paramObj + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value " + paramObj + " for parameter " + parameterAnnotation.name()); } catch (ParseException parseEx) { if (s_logger.isDebugEnabled()) { s_logger.debug("Invalid date parameter " + paramObj + " passed to command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8)); } - throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + ", please pass dates in the format mentioned in the api documentation"); } catch (InvalidParameterValueException invEx) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage()); } catch (CloudRuntimeException cloudEx) { // FIXME: Better error message? This only happens if the API command is not executable, which typically //means // there was // and IllegalAccessException setting one of the parameters. - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal error executing API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8)); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Internal error executing API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8)); } //check access on the resource this field points to diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index e106f0322ad..fc197b943e6 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -101,6 +101,8 @@ import org.apache.cloudstack.api.command.user.tag.ListTagsCmd; import com.cloud.api.response.ApiResponseSerializer; import org.apache.cloudstack.api.response.ExceptionResponse; import org.apache.cloudstack.api.response.ListResponse; + +import com.cloud.async.AsyncCommandQueued; import com.cloud.async.AsyncJob; import com.cloud.async.AsyncJobManager; import com.cloud.async.AsyncJobVO; @@ -111,9 +113,13 @@ import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.domain.Domain; import com.cloud.domain.DomainVO; import com.cloud.event.EventUtils; +import com.cloud.exception.AccountLimitException; import com.cloud.exception.CloudAuthenticationException; +import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.server.ManagementServer; import com.cloud.user.Account; import com.cloud.user.AccountManager; @@ -130,7 +136,7 @@ import com.cloud.utils.component.Inject; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; -import com.cloud.utils.exception.CSExceptionErrorCode; + public class ApiServer implements HttpRequestHandler { private static final Logger s_logger = Logger.getLogger(ApiServer.class.getName()); @@ -272,8 +278,8 @@ public class ApiServer implements HttpRequestHandler { writeResponse(response, responseText, HttpStatus.SC_OK, responseType, null); } catch (ServerApiException se) { - String responseText = getSerializedApiError(se.getErrorCode(), se.getDescription(), parameterMap, responseType, se); - writeResponse(response, responseText, se.getErrorCode(), responseType, se.getDescription()); + String responseText = getSerializedApiError(se, parameterMap, responseType); + writeResponse(response, responseText, se.getErrorCode().getHttpCode(), responseType, se.getDescription()); sb.append(" " + se.getErrorCode() + " " + se.getDescription()); } catch (RuntimeException e) { // log runtime exception like NullPointerException to help identify the source easier @@ -302,7 +308,7 @@ public class ApiServer implements HttpRequestHandler { s_logger.trace(" key: " + keyStr + ", value: " + ((value == null) ? "'null'" : value[0])); } } - throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "Invalid request, no command sent"); + throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "Invalid request, no command sent"); } else { Map paramMap = new HashMap(); Set keys = params.keySet(); @@ -320,10 +326,10 @@ public class ApiServer implements HttpRequestHandler { decodedValue = URLDecoder.decode(value[0], "UTF-8"); } catch (UnsupportedEncodingException usex) { s_logger.warn(key + " could not be decoded, value = " + value[0]); - throw new ServerApiException(BaseCmd.PARAM_ERROR, key + " could not be decoded, received value " + value[0]); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, key + " could not be decoded, received value " + value[0]); } catch (IllegalArgumentException iae) { s_logger.warn(key + " could not be decoded, value = " + value[0]); - throw new ServerApiException(BaseCmd.PARAM_ERROR, key + " could not be decoded, received value " + value[0] + " which contains illegal characters eg.%"); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, key + " could not be decoded, received value " + value[0] + " which contains illegal characters eg.%"); } } else { decodedValue = value[0]; @@ -344,51 +350,81 @@ public class ApiServer implements HttpRequestHandler { String errorString = "Unknown API command: " + ((command == null) ? "null" : command[0]); s_logger.warn(errorString); auditTrailSb.append(" " + errorString); - throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, errorString); + throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, errorString); } } } - } catch (Exception ex) { - if (ex instanceof InvalidParameterValueException) { - InvalidParameterValueException ref = (InvalidParameterValueException)ex; - ServerApiException e = new ServerApiException(BaseCmd.PARAM_ERROR, ex.getMessage()); - // copy over the IdentityProxy information as well and throw the serverapiexception. - ArrayList idList = ref.getIdProxyList(); - if (idList != null) { - // Iterate through entire arraylist and copy over each proxy id. - for (int i = 0 ; i < idList.size(); i++) { - e.addProxyObject(idList.get(i)); - } - } - // Also copy over the cserror code and the function/layer in which it was thrown. - e.setCSErrorCode(ref.getCSErrorCode()); - throw e; - } else if (ex instanceof PermissionDeniedException) { - PermissionDeniedException ref = (PermissionDeniedException)ex; - ServerApiException e = new ServerApiException(BaseCmd.ACCOUNT_ERROR, ex.getMessage()); - // copy over the IdentityProxy information as well and throw the serverapiexception. - ArrayList idList = ref.getIdProxyList(); - if (idList != null) { - // Iterate through entire arraylist and copy over each proxy id. - for (int i = 0 ; i < idList.size(); i++) { - e.addProxyObject(idList.get(i)); - } - } - e.setCSErrorCode(ref.getCSErrorCode()); - throw e; - } else if (ex instanceof ServerApiException) { - throw (ServerApiException) ex; - } else { - s_logger.error("unhandled exception executing api command: " + ((command == null) ? "null" : command[0]), ex); - ServerApiException e = new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal server error, unable to execute request."); - e.setCSErrorCode(CSExceptionErrorCode.getCSErrCode("ServerApiException")); - throw e; - } } + catch (InvalidParameterValueException ex){ + s_logger.info(ex.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage(), ex); + } + catch (IllegalArgumentException ex){ + s_logger.info(ex.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage(), ex); + } + catch (PermissionDeniedException ex){ + ArrayList idList = ex.getIdProxyList(); + if (idList != null) { + s_logger.info("PermissionDenied: " + ex.getMessage() + " on uuids: [" + StringUtils.listToCsvTags(idList) + "]"); + } else { + s_logger.info("PermissionDenied: " + ex.getMessage()); + } + throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, ex.getMessage(), ex); + } + catch (AccountLimitException ex){ + s_logger.info(ex.getMessage()); + throw new ServerApiException(ApiErrorCode.ACCOUNT_RESOURCE_LIMIT_ERROR, ex.getMessage(), ex); + } + catch (InsufficientCapacityException ex){ + s_logger.info(ex.getMessage()); + String errorMsg = ex.getMessage(); + if (UserContext.current().getCaller().getType() != Account.ACCOUNT_TYPE_ADMIN){ + // hide internal details to non-admin user for security reason + errorMsg = BaseCmd.USER_ERROR_MESSAGE; + } + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, errorMsg, ex); + } + catch (ResourceAllocationException ex){ + s_logger.info(ex.getMessage()); + String errorMsg = ex.getMessage(); + if (UserContext.current().getCaller().getType() != Account.ACCOUNT_TYPE_ADMIN){ + // hide internal details to non-admin user for security reason + errorMsg = BaseCmd.USER_ERROR_MESSAGE; + } + throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, errorMsg, ex); + } + catch (ResourceUnavailableException ex){ + s_logger.info(ex.getMessage()); + String errorMsg = ex.getMessage(); + if (UserContext.current().getCaller().getType() != Account.ACCOUNT_TYPE_ADMIN){ + // hide internal details to non-admin user for security reason + errorMsg = BaseCmd.USER_ERROR_MESSAGE; + } + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, errorMsg, ex); + } + catch (AsyncCommandQueued ex){ + s_logger.error("unhandled exception executing api command: " + ((command == null) ? "null" : command[0]), ex); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Internal server error, unable to execute request."); + } + catch (ServerApiException ex){ + s_logger.info(ex.getDescription()); + throw ex; + } + catch (Exception ex){ + s_logger.error("unhandled exception executing api command: " + ((command == null) ? "null" : command[0]), ex); + String errorMsg = ex.getMessage(); + if (UserContext.current().getCaller().getType() != Account.ACCOUNT_TYPE_ADMIN){ + // hide internal details to non-admin user for security reason + errorMsg = BaseCmd.USER_ERROR_MESSAGE; + } + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMsg, ex); + } + return response; } - private String queueCommand(BaseCmd cmdObj, Map params) { + private String queueCommand(BaseCmd cmdObj, Map params) throws Exception { UserContext ctx = UserContext.current(); Long callerUserId = ctx.getCallerUserId(); Account caller = ctx.getCaller(); @@ -444,7 +480,7 @@ public class ApiServer implements HttpRequestHandler { if (jobId == 0L) { String errorMsg = "Unable to schedule async job for command " + job.getCmd(); s_logger.warn(errorMsg); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, errorMsg); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMsg); } if (objectId != null) { @@ -554,14 +590,14 @@ public class ApiServer implements HttpRequestHandler { } catch (PermissionDeniedException ex){ s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user with id:" + userId); - throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user"); + throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user"); } return true; } else { // check against every available command to see if the command exists or not if (!_apiNameCmdClassMap.containsKey(commandName) && !commandName.equals("login") && !commandName.equals("logout")) { s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user with id:" + userId); - throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user"); + throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user"); } } @@ -657,7 +693,7 @@ public class ApiServer implements HttpRequestHandler { } catch (PermissionDeniedException ex){ s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user"); - throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "The given command:" + commandName + " does not exist or it is not available for user with id:" + userId); + throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "The given command:" + commandName + " does not exist or it is not available for user with id:" + userId); } // verify secret key exists @@ -680,11 +716,10 @@ public class ApiServer implements HttpRequestHandler { s_logger.info("User signature: " + signature + " is not equaled to computed signature: " + computedSignature); } return equalSig; - } catch (Exception ex) { - if (ex instanceof ServerApiException && ((ServerApiException) ex).getErrorCode() == BaseCmd.UNSUPPORTED_ACTION_ERROR) { - throw (ServerApiException) ex; - } - s_logger.error("unable to verify request signature", ex); + } catch (ServerApiException ex){ + throw ex; + } catch (Exception ex){ + s_logger.error("unable to verify request signature"); } return false; } @@ -931,13 +966,13 @@ public class ApiServer implements HttpRequestHandler { } } - public String getSerializedApiError(int errorCode, String errorText, Map apiCommandParams, String responseType, Exception ex) { + public String getSerializedApiError(int errorCode, String errorText, Map apiCommandParams, String responseType) { String responseName = null; Class cmdClass = null; String responseText = null; try { - if (errorCode == BaseCmd.UNSUPPORTED_ACTION_ERROR || apiCommandParams == null || apiCommandParams.isEmpty()) { + if (apiCommandParams == null || apiCommandParams.isEmpty()) { responseName = "errorresponse"; } else { Object cmdObj = apiCommandParams.get("command"); @@ -956,48 +991,55 @@ public class ApiServer implements HttpRequestHandler { apiResponse.setErrorCode(errorCode); apiResponse.setErrorText(errorText); apiResponse.setResponseName(responseName); - // Also copy over the IdentityProxy object List into this new apiResponse, from - // the exception caught. When invoked from handle(), the exception here can - // be either ServerApiException, PermissionDeniedException or InvalidParameterValue - // Exception. When invoked from ApiServlet's processRequest(), this can be - // a standard exception like NumberFormatException. We'll leave the standard ones alone. - if (ex != null) { - if (ex instanceof ServerApiException || ex instanceof PermissionDeniedException - || ex instanceof InvalidParameterValueException) { - // Cast the exception appropriately and retrieve the IdentityProxy - if (ex instanceof ServerApiException) { - ServerApiException ref = (ServerApiException) ex; - ArrayList idList = ref.getIdProxyList(); - if (idList != null) { - for (int i=0; i < idList.size(); i++) { - apiResponse.addProxyObject(idList.get(i)); - } - } - // Also copy over the cserror code and the function/layer in which it was thrown. - apiResponse.setCSErrorCode(ref.getCSErrorCode()); - } else if (ex instanceof PermissionDeniedException) { - PermissionDeniedException ref = (PermissionDeniedException) ex; - ArrayList idList = ref.getIdProxyList(); - if (idList != null) { - for (int i=0; i < idList.size(); i++) { - apiResponse.addProxyObject(idList.get(i)); - } - } - // Also copy over the cserror code and the function/layer in which it was thrown. - apiResponse.setCSErrorCode(ref.getCSErrorCode()); - } else if (ex instanceof InvalidParameterValueException) { - InvalidParameterValueException ref = (InvalidParameterValueException) ex; - ArrayList idList = ref.getIdProxyList(); - if (idList != null) { - for (int i=0; i < idList.size(); i++) { - apiResponse.addProxyObject(idList.get(i)); - } - } - // Also copy over the cserror code and the function/layer in which it was thrown. - apiResponse.setCSErrorCode(ref.getCSErrorCode()); - } - } + SerializationContext.current().setUuidTranslation(true); + responseText = ApiResponseSerializer.toSerializedString(apiResponse, responseType); + + } catch (Exception e) { + s_logger.error("Exception responding to http request", e); + } + return responseText; + } + + public String getSerializedApiError(ServerApiException ex, Map apiCommandParams, String responseType) { + String responseName = null; + Class cmdClass = null; + String responseText = null; + + if (ex == null){ + // this call should not be invoked with null exception + return getSerializedApiError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Some internal error happened", apiCommandParams, responseType); + } + try { + if (ex.getErrorCode() == ApiErrorCode.UNSUPPORTED_ACTION_ERROR || apiCommandParams == null || apiCommandParams.isEmpty()) { + responseName = "errorresponse"; + } else { + Object cmdObj = apiCommandParams.get("command"); + // cmd name can be null when "command" parameter is missing in + // the request + if (cmdObj != null) { + String cmdName = ((String[]) cmdObj)[0]; + cmdClass = getCmdClass(cmdName); + if (cmdClass != null) { + responseName = ((BaseCmd) cmdClass.newInstance()).getCommandName(); + } else { + responseName = "errorresponse"; + } + } } + ExceptionResponse apiResponse = new ExceptionResponse(); + apiResponse.setErrorCode(ex.getErrorCode().getHttpCode()); + apiResponse.setErrorText(ex.getDescription()); + apiResponse.setResponseName(responseName); + ArrayList idList = ex.getIdProxyList(); + if (idList != null) { + for (int i = 0; i < idList.size(); i++) { + apiResponse.addProxyObject(idList.get(i)); + } + } + // Also copy over the cserror code and the function/layer in which + // it was thrown. + apiResponse.setCSErrorCode(ex.getCSErrorCode()); + SerializationContext.current().setUuidTranslation(true); responseText = ApiResponseSerializer.toSerializedString(apiResponse, responseType); diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java index 19091f25ff2..92d3137d30a 100755 --- a/server/src/com/cloud/api/ApiServlet.java +++ b/server/src/com/cloud/api/ApiServlet.java @@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.ServerApiException; import org.apache.log4j.Logger; @@ -128,7 +129,7 @@ public class ApiServlet extends HttpServlet { reqStr = auditTrailSb.toString() + " " + req.getQueryString(); s_logger.debug("===START=== " + StringUtils.cleanString(reqStr)); } - + try { HttpSession session = req.getSession(false); Object[] responseTypeParam = params.get("response"); @@ -192,7 +193,7 @@ public class ApiServlet extends HttpServlet { s_logger.warn("Invalid domain id entered by user"); auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "Invalid domain id entered, please enter a valid one"); String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid domain id entered, please enter a valid one", params, - responseType, null); + responseType); writeResponse(resp, serializedResponse, HttpServletResponse.SC_UNAUTHORIZED, responseType); } } @@ -227,10 +228,10 @@ public class ApiServlet extends HttpServlet { } catch (IllegalStateException ise) { } - auditTrailSb.append(" " + BaseCmd.ACCOUNT_ERROR + " " + ex.getMessage() != null ? ex.getMessage() : "failed to authenticate user, check if username/password are correct"); - String serializedResponse = _apiServer.getSerializedApiError(BaseCmd.ACCOUNT_ERROR, ex.getMessage() != null ? ex.getMessage() - : "failed to authenticate user, check if username/password are correct", params, responseType, null); - writeResponse(resp, serializedResponse, BaseCmd.ACCOUNT_ERROR, responseType); + auditTrailSb.append(" " + ApiErrorCode.ACCOUNT_ERROR + " " + ex.getMessage() != null ? ex.getMessage() : "failed to authenticate user, check if username/password are correct"); + String serializedResponse = _apiServer.getSerializedApiError(ApiErrorCode.ACCOUNT_ERROR.getHttpCode(), ex.getMessage() != null ? ex.getMessage() + : "failed to authenticate user, check if username/password are correct", params, responseType); + writeResponse(resp, serializedResponse, ApiErrorCode.ACCOUNT_ERROR.getHttpCode(), responseType); return; } } @@ -257,7 +258,7 @@ public class ApiServlet extends HttpServlet { } catch (IllegalStateException ise) { } auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "unable to verify user credentials"); - String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials", params, responseType, null); + String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials", params, responseType); writeResponse(resp, serializedResponse, HttpServletResponse.SC_UNAUTHORIZED, responseType); return; } @@ -269,7 +270,7 @@ public class ApiServlet extends HttpServlet { if (command == null) { s_logger.info("missing command, ignoring request..."); auditTrailSb.append(" " + HttpServletResponse.SC_BAD_REQUEST + " " + "no command specified"); - String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_BAD_REQUEST, "no command specified", params, responseType, null); + String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_BAD_REQUEST, "no command specified", params, responseType); writeResponse(resp, serializedResponse, HttpServletResponse.SC_BAD_REQUEST, responseType); return; } @@ -283,7 +284,7 @@ public class ApiServlet extends HttpServlet { } auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "unable to verify user credentials"); - String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials", params, responseType, null); + String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials", params, responseType); writeResponse(resp, serializedResponse, HttpServletResponse.SC_UNAUTHORIZED, responseType); return; } @@ -298,7 +299,7 @@ public class ApiServlet extends HttpServlet { * params.put(BaseCmd.Properties.ACCOUNT_OBJ.getName(), new Object[] { accountObj }); } else { * params.put(BaseCmd.Properties.USER_ID.getName(), new String[] { userId }); * params.put(BaseCmd.Properties.ACCOUNT_OBJ.getName(), new Object[] { accountObj }); } } - * + * * // update user context info here so that we can take information if the request is authenticated // via api * key mechanism updateUserContext(params, session != null ? session.getId() : null); */ @@ -307,15 +308,9 @@ public class ApiServlet extends HttpServlet { "(userId=" + UserContext.current().getCallerUserId() + " accountId=" + UserContext.current().getCaller().getId() + " sessionId=" + (session != null ? session.getId() : null) + ")"); - try { - String response = _apiServer.handleRequest(params, false, responseType, auditTrailSb); - writeResponse(resp, response != null ? response : "", HttpServletResponse.SC_OK, responseType); - } catch (ServerApiException se) { - String serializedResponseText = _apiServer.getSerializedApiError(se.getErrorCode(), se.getDescription(), params, responseType, null); - resp.setHeader("X-Description", se.getDescription()); - writeResponse(resp, serializedResponseText, se.getErrorCode(), responseType); - auditTrailSb.append(" " + se.getErrorCode() + " " + se.getDescription()); - } + String response = _apiServer.handleRequest(params, false, responseType, auditTrailSb); + writeResponse(resp, response != null ? response : "", HttpServletResponse.SC_OK, responseType); + } else { if (session != null) { try { @@ -325,21 +320,18 @@ public class ApiServlet extends HttpServlet { } auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "unable to verify user credentials and/or request signature"); - String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials and/or request signature", params, responseType, null); + String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials and/or request signature", params, responseType); writeResponse(resp, serializedResponse, HttpServletResponse.SC_UNAUTHORIZED, responseType); } + } catch (ServerApiException se) { + String serializedResponseText = _apiServer.getSerializedApiError(se, params, responseType); + resp.setHeader("X-Description", se.getDescription()); + writeResponse(resp, serializedResponseText, se.getErrorCode().getHttpCode(), responseType); + auditTrailSb.append(" " + se.getErrorCode() + " " + se.getDescription()); } catch (Exception ex) { - if (ex instanceof ServerApiException && ((ServerApiException) ex).getErrorCode() == BaseCmd.UNSUPPORTED_ACTION_ERROR) { - ServerApiException se = (ServerApiException) ex; - String serializedResponseText = _apiServer.getSerializedApiError(se.getErrorCode(), se.getDescription(), params, responseType, null); - resp.setHeader("X-Description", se.getDescription()); - writeResponse(resp, serializedResponseText, se.getErrorCode(), responseType); - auditTrailSb.append(" " + se.getErrorCode() + " " + se.getDescription()); - } else { - s_logger.error("unknown exception writing api response", ex); - auditTrailSb.append(" unknown exception writing api response"); - } + s_logger.error("unknown exception writing api response", ex); + auditTrailSb.append(" unknown exception writing api response"); } finally { s_accessLogger.info(auditTrailSb.toString()); if (s_logger.isDebugEnabled()) { @@ -354,9 +346,9 @@ public class ApiServlet extends HttpServlet { * private void updateUserContext(Map requestParameters, String sessionId) { String userIdStr = * (String)(requestParameters.get(BaseCmd.Properties.USER_ID.getName())[0]); Account accountObj = * (Account)(requestParameters.get(BaseCmd.Properties.ACCOUNT_OBJ.getName())[0]); - * + * * Long userId = null; Long accountId = null; if(userIdStr != null) userId = Long.parseLong(userIdStr); - * + * * if(accountObj != null) accountId = accountObj.getId(); UserContext.updateContext(userId, accountId, sessionId); } */ @@ -386,7 +378,7 @@ public class ApiServlet extends HttpServlet { private String getLoginSuccessResponse(HttpSession session, String responseType) { StringBuffer sb = new StringBuffer(); int inactiveInterval = session.getMaxInactiveInterval(); - + String user_UUID = (String)session.getAttribute("user_UUID"); session.removeAttribute("user_UUID"); diff --git a/server/src/com/cloud/api/commands/AddTrafficMonitorCmd.java b/server/src/com/cloud/api/commands/AddTrafficMonitorCmd.java index fdbbbe4ca3c..cdf83ae9ab6 100644 --- a/server/src/com/cloud/api/commands/AddTrafficMonitorCmd.java +++ b/server/src/com/cloud/api/commands/AddTrafficMonitorCmd.java @@ -97,9 +97,9 @@ public class AddTrafficMonitorCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException ipve) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, ipve.getMessage()); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage()); } catch (CloudRuntimeException cre) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, cre.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage()); } } } diff --git a/server/src/com/cloud/api/commands/DeleteTrafficMonitorCmd.java b/server/src/com/cloud/api/commands/DeleteTrafficMonitorCmd.java index 4c7d3a70546..d39323aa60d 100644 --- a/server/src/com/cloud/api/commands/DeleteTrafficMonitorCmd.java +++ b/server/src/com/cloud/api/commands/DeleteTrafficMonitorCmd.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.HostResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.Parameter; @@ -33,25 +34,25 @@ import com.cloud.utils.component.ComponentLocator; @APICommand(name = "deleteTrafficMonitor", description="Deletes an traffic monitor host.", responseObject = SuccessResponse.class) public class DeleteTrafficMonitorCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTrafficMonitorCmd.class.getName()); - private static final String s_name = "deletetrafficmonitorresponse"; - + public static final Logger s_logger = Logger.getLogger(DeleteTrafficMonitorCmd.class.getName()); + private static final String s_name = "deletetrafficmonitorresponse"; + ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = HostResponse.class, required = true, description="Id of the Traffic Monitor Host.") private Long id; - + /////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - + public Long getId() { return id; } - + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -60,12 +61,12 @@ public class DeleteTrafficMonitorCmd extends BaseCmd { public String getCommandName() { return s_name; } - + @Override public long getEntityOwnerId() { return Account.ACCOUNT_ID_SYSTEM; } - + @Override public void execute(){ try { @@ -77,10 +78,10 @@ public class DeleteTrafficMonitorCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete traffic monitor."); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete traffic monitor."); } } catch (InvalidParameterValueException e) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, "Failed to delete traffic monitor."); + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Failed to delete traffic monitor."); } } } diff --git a/server/src/com/cloud/api/commands/GenerateUsageRecordsCmd.java b/server/src/com/cloud/api/commands/GenerateUsageRecordsCmd.java index aa3c082ce81..4206cf82885 100644 --- a/server/src/com/cloud/api/commands/GenerateUsageRecordsCmd.java +++ b/server/src/com/cloud/api/commands/GenerateUsageRecordsCmd.java @@ -85,7 +85,7 @@ public class GenerateUsageRecordsCmd extends BaseCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to generate usage records"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate usage records"); } } } diff --git a/server/src/com/cloud/async/AsyncJobManagerImpl.java b/server/src/com/cloud/async/AsyncJobManagerImpl.java index 7bf5c5a83cc..05d305eef6e 100644 --- a/server/src/com/cloud/async/AsyncJobManagerImpl.java +++ b/server/src/com/cloud/async/AsyncJobManagerImpl.java @@ -41,6 +41,8 @@ import org.apache.log4j.NDC; import com.cloud.api.ApiDispatcher; import com.cloud.api.ApiGsonHelper; import com.cloud.api.ApiSerializerHelper; + +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.ServerApiException; @@ -78,13 +80,13 @@ import com.google.gson.reflect.TypeToken; public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListener { public static final Logger s_logger = Logger.getLogger(AsyncJobManagerImpl.class.getName()); private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 3; // 3 seconds - + private static final int MAX_ONETIME_SCHEDULE_SIZE = 50; private static final int HEARTBEAT_INTERVAL = 2000; private static final int GC_INTERVAL = 10000; // 10 seconds - + private String _name; - + private AsyncJobExecutorContext _context; private SyncQueueManager _queueMgr; private ClusterManager _clusterMgr; @@ -93,7 +95,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe private AsyncJobDao _jobDao; private long _jobExpireSeconds = 86400; // 1 day private long _jobCancelThresholdSeconds = 3600; // 1 hour (for cancelling the jobs blocking other jobs) - + private ApiDispatcher _dispatcher; private final ScheduledExecutorService _heartbeatScheduler = @@ -104,7 +106,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe public AsyncJobExecutorContext getExecutorContext() { return _context; } - + @Override public AsyncJobVO getAsyncJob(long jobId) { return _jobDao.findById(jobId); @@ -119,7 +121,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe public List findInstancePendingAsyncJobs(AsyncJob.Type instanceType, Long accountId) { return _jobDao.findInstancePendingAsyncJobs(instanceType, accountId); } - + @Override public long submitAsyncJob(AsyncJobVO job) { return submitAsyncJob(job, false); @@ -155,7 +157,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe s_logger.debug("Complete async job-" + jobId + ", jobStatus: " + jobStatus + ", resultCode: " + resultCode + ", result: " + resultObject); } - + Transaction txt = Transaction.currentTxn(); try { txt.start(); @@ -165,7 +167,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe s_logger.debug("job-" + jobId + " no longer exists, we just log completion info here. " + jobStatus + ", resultCode: " + resultCode + ", result: " + resultObject); } - + txt.rollback(); return; } @@ -197,7 +199,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe s_logger.debug("Update async-job progress, job-" + jobId + ", processStatus: " + processStatus + ", result: " + resultObject); } - + Transaction txt = Transaction.currentTxn(); try { txt.start(); @@ -206,11 +208,11 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe if(s_logger.isDebugEnabled()) { s_logger.debug("job-" + jobId + " no longer exists, we just log progress info here. progress status: " + processStatus); } - + txt.rollback(); return; } - + job.setProcessStatus(processStatus); if(resultObject != null) { job.setResult(ApiSerializerHelper.toSerializedStringOld(resultObject)); @@ -258,7 +260,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe if (job.getSyncSource() != null) { return; } - + if(s_logger.isDebugEnabled()) { s_logger.debug("Sync job-" + job.getId() + " execution on object " + syncObjType + "." + syncObjId); } @@ -287,7 +289,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe throw new AsyncCommandQueued(queue, "job-" + job.getId() + " queued"); } } - + @Override public AsyncJob queryAsyncJobResult(QueryAsyncJobResultCmd cmd) { Account caller = UserContext.current().getCaller(); @@ -296,10 +298,10 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe if (job == null) { throw new InvalidParameterValueException("Unable to find a job by id " + cmd.getId()); } - + User userJobOwner = _accountMgr.getUserIncludingRemoved(job.getUserId()); Account jobOwner = _accountMgr.getAccount(userJobOwner.getAccountId()); - + //check permissions if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) { //regular user can see only jobs he owns @@ -309,7 +311,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe } else if (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) { _accountMgr.checkAccess(caller, null, true, jobOwner); } - + //poll the job queryAsyncJobResult(cmd.getId()); return _jobDao.findById(cmd.getId()); @@ -320,10 +322,10 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe if(s_logger.isTraceEnabled()) { s_logger.trace("Query async-job status, job-" + jobId); } - + Transaction txt = Transaction.currentTxn(); AsyncJobResult jobResult = new AsyncJobResult(jobId); - + try { txt.start(); AsyncJobVO job = _jobDao.findById(jobId); @@ -334,10 +336,10 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe jobResult.setResult(job.getResult()); jobResult.setResultCode(job.getResultCode()); jobResult.setUuid(job.getUuid()); - + if(job.getStatus() == AsyncJobResult.STATUS_SUCCEEDED || job.getStatus() == AsyncJobResult.STATUS_FAILED) { - + if(s_logger.isDebugEnabled()) { s_logger.debug("Async job-" + jobId + " completed"); } @@ -349,23 +351,23 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe if(s_logger.isDebugEnabled()) { s_logger.debug("Async job-" + jobId + " does not exist, invalid job id?"); } - + jobResult.setJobStatus(AsyncJobResult.STATUS_FAILED); jobResult.setResult("job-" + jobId + " does not exist"); } txt.commit(); } catch(Exception e) { s_logger.error("Unexpected exception while querying async job-" + jobId + " status: ", e); - + jobResult.setJobStatus(AsyncJobResult.STATUS_FAILED); jobResult.setResult("Exception: " + e.toString()); txt.rollback(); } - + if(s_logger.isTraceEnabled()) { s_logger.trace("Job status: " + jobResult.toString()); } - + return jobResult; } @@ -388,66 +390,66 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe public void run() { try { long jobId = 0; - + try { JmxUtil.registerMBean("AsyncJobManager", "Active Job " + job.getId(), new AsyncJobMBeanImpl(job)); } catch(Exception e) { s_logger.warn("Unable to register active job " + job.getId() + " to JMX monitoring due to exception " + ExceptionUtil.toString(e)); } - + BaseAsyncCmd cmdObj = null; Transaction txn = Transaction.open(Transaction.CLOUD_DB); try { jobId = job.getId(); NDC.push("job-" + jobId); - + if(s_logger.isDebugEnabled()) { s_logger.debug("Executing " + job.getCmd() + " for job-" + jobId); } - + Class cmdClass = Class.forName(job.getCmd()); cmdObj = (BaseAsyncCmd)cmdClass.newInstance(); cmdObj.setJob(job); - + Type mapType = new TypeToken>() {}.getType(); Gson gson = ApiGsonHelper.getBuilder().create(); Map params = gson.fromJson(job.getCmdInfo(), mapType); - + // whenever we deserialize, the UserContext needs to be updated String userIdStr = params.get("ctxUserId"); String acctIdStr = params.get("ctxAccountId"); Long userId = null; Account accountObject = null; - + if (userIdStr != null) { userId = Long.parseLong(userIdStr); } - + if (acctIdStr != null) { accountObject = _accountDao.findById(Long.parseLong(acctIdStr)); } - + UserContext.registerContext(userId, accountObject, null, false); try { // dispatch could ultimately queue the job _dispatcher.dispatch(cmdObj, params); - + // serialize this to the async job table completeAsyncJob(jobId, AsyncJobResult.STATUS_SUCCEEDED, 0, cmdObj.getResponseObject()); } finally { UserContext.unregisterContext(); } - + // commands might need to be queued as part of synchronization here, so they just have to be re-dispatched from the queue mechanism... if (job.getSyncSource() != null) { _queueMgr.purgeItem(job.getSyncSource().getId()); checkQueue(job.getSyncSource().getQueueId()); } - + if (s_logger.isDebugEnabled()) { s_logger.debug("Done executing " + job.getCmd() + " for job-" + jobId); } - + } catch(Throwable e) { if (e instanceof AsyncCommandQueued) { if (s_logger.isDebugEnabled()) { @@ -456,25 +458,25 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe checkQueue(((AsyncCommandQueued)e).getQueue().getId()); } else { String errorMsg = null; - int errorCode = BaseCmd.INTERNAL_ERROR; + int errorCode = ApiErrorCode.INTERNAL_ERROR.getHttpCode(); if (!(e instanceof ServerApiException)) { s_logger.error("Unexpected exception while executing " + job.getCmd(), e); errorMsg = e.getMessage(); } else { ServerApiException sApiEx = (ServerApiException)e; errorMsg = sApiEx.getDescription(); - errorCode = sApiEx.getErrorCode(); + errorCode = sApiEx.getErrorCode().getHttpCode(); } - + ExceptionResponse response = new ExceptionResponse(); response.setErrorCode(errorCode); response.setErrorText(errorMsg); response.setResponseName((cmdObj == null) ? "unknowncommandresponse" : cmdObj.getCommandName()); - - // FIXME: setting resultCode to BaseCmd.INTERNAL_ERROR is not right, usually executors have their exception handling + + // FIXME: setting resultCode to ApiErrorCode.INTERNAL_ERROR is not right, usually executors have their exception handling // and we need to preserve that as much as possible here - completeAsyncJob(jobId, AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR, response); - + completeAsyncJob(jobId, AsyncJobResult.STATUS_FAILED, ApiErrorCode.INTERNAL_ERROR.getHttpCode(), response); + // need to clean up any queue that happened as part of the dispatching and move on to the next item in the queue try { if (job.getSyncSource() != null) { @@ -486,13 +488,13 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe } } } finally { - + try { JmxUtil.unregisterMBean("AsyncJobManager", "Active Job " + job.getId()); } catch(Exception e) { s_logger.warn("Unable to unregister active job " + job.getId() + " from JMX monitoring"); } - + StackMaid.current().exitCleanup(); txn.close(); NDC.pop(); @@ -516,17 +518,17 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe job.setFromPreviousSession(fromPreviousSession); job.setSyncSource(item); - + job.setCompleteMsid(getMsid()); _jobDao.update(job.getId(), job); - + try { scheduleExecution(job); } catch(RejectedExecutionException e) { s_logger.warn("Execution for job-" + job.getId() + " is rejected, return it to the queue for next turn"); _queueMgr.returnItem(item.getId()); } - + } else { if(s_logger.isDebugEnabled()) { s_logger.debug("Unable to find related job for queue item: " + item.toString()); @@ -544,12 +546,12 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe + executor.getSyncSource().getContentType() + "-" + executor.getSyncSource().getContentId()); } - + _queueMgr.purgeItem(executor.getSyncSource().getId()); checkQueue(executor.getSyncSource().getQueueId()); } } - + private void checkQueue(long queueId) { while(true) { try { @@ -558,7 +560,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe if(s_logger.isDebugEnabled()) { s_logger.debug("Executing sync queue item: " + item.toString()); } - + executeQueueItem(item, false); } else { break; @@ -569,7 +571,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe } } } - + private Runnable getHeartbeatTask() { return new Runnable() { @Override @@ -592,7 +594,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe } }; } - + @DB private Runnable getGCTask() { return new Runnable() { @@ -611,7 +613,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe scanLock.releaseRef(); } } - + public void reallyRun() { try { s_logger.trace("Begin cleanup expired async-jobs"); @@ -649,10 +651,10 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe } } - + }; } - + @DB protected void expungeAsyncJob(AsyncJobVO job) { Transaction txn = Transaction.currentTxn(); @@ -667,10 +669,10 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe if(_clusterMgr != null) { return _clusterMgr.getManagementNodeId(); } - + return MacAddress.getMacAddress().toLong(); } - + private void cleanupPendingJobs(List l) { if(l != null && l.size() > 0) { for(SyncQueueItemVO item: l) { @@ -701,7 +703,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe if (configDao == null) { throw new ConfigurationException("Unable to get the configuration dao."); } - + int expireMinutes = NumbersUtil.parseInt( configDao.getValue(Config.JobExpireMinutes.key()), 24*60); _jobExpireSeconds = (long)expireMinutes*60; @@ -719,48 +721,48 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe throw new ConfigurationException("Unable to get " + AsyncJobDao.class.getName()); } - + _context = locator.getManager(AsyncJobExecutorContext.class); if (_context == null) { throw new ConfigurationException("Unable to get " + AsyncJobExecutorContext.class.getName()); } - + _queueMgr = locator.getManager(SyncQueueManager.class); if(_queueMgr == null) { throw new ConfigurationException("Unable to get " + SyncQueueManager.class.getName()); } - + _clusterMgr = locator.getManager(ClusterManager.class); - + _accountMgr = locator.getManager(AccountManager.class); _dispatcher = ApiDispatcher.getInstance(); - + try { final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties"); final Properties dbProps = new Properties(); dbProps.load(new FileInputStream(dbPropsFile)); - + final int cloudMaxActive = Integer.parseInt(dbProps.getProperty("db.cloud.maxActive")); - + int poolSize = (cloudMaxActive * 2) / 3; - + s_logger.info("Start AsyncJobManager thread pool in size " + poolSize); _executor = Executors.newFixedThreadPool(poolSize, new NamedThreadFactory("Job-Executor")); } catch (final Exception e) { throw new ConfigurationException("Unable to load db.properties to configure AsyncJobManagerImpl"); } - + return true; } - + @Override public void onManagementNodeJoined(List nodeList, long selfNodeId) { } - + @Override public void onManagementNodeLeft(List nodeList, long selfNodeId) { for(ManagementServerHostVO msHost : nodeList) { @@ -769,7 +771,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe txn.start(); List items = _queueMgr.getActiveQueueItems(msHost.getId(), true); cleanupPendingJobs(items); - _jobDao.resetJobProcess(msHost.getId(), BaseCmd.INTERNAL_ERROR, getSerializedErrorMessage("job cancelled because of management server restart")); + _jobDao.resetJobProcess(msHost.getId(), ApiErrorCode.INTERNAL_ERROR.getHttpCode(), getSerializedErrorMessage("job cancelled because of management server restart")); txn.commit(); } catch(Throwable e) { s_logger.warn("Unexpected exception ", e); @@ -779,7 +781,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe } } } - + @Override public void onManagementNodeIsolated() { } @@ -789,7 +791,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe try { List l = _queueMgr.getActiveQueueItems(getMsid(), false); cleanupPendingJobs(l); - _jobDao.resetJobProcess(getMsid(), BaseCmd.INTERNAL_ERROR, getSerializedErrorMessage("job cancelled because of management server restart")); + _jobDao.resetJobProcess(getMsid(), ApiErrorCode.INTERNAL_ERROR.getHttpCode(), getSerializedErrorMessage("job cancelled because of management server restart")); } catch(Throwable e) { s_logger.error("Unexpected exception " + e.getMessage(), e); } @@ -801,14 +803,14 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe return true; } - + private static ExceptionResponse getResetResultResponse(String errorMessage) { ExceptionResponse resultObject = new ExceptionResponse(); - resultObject.setErrorCode(BaseCmd.INTERNAL_ERROR); + resultObject.setErrorCode(ApiErrorCode.INTERNAL_ERROR.getHttpCode()); resultObject.setErrorText(errorMessage); return resultObject; } - + private static String getSerializedErrorMessage(String errorMessage) { return ApiSerializerHelper.toSerializedStringOld(getResetResultResponse(errorMessage)); } @@ -819,7 +821,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe _executor.shutdown(); return true; } - + @Override public String getName() { return _name; diff --git a/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java b/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java index 303e0d681fa..1a0969957a6 100755 --- a/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java +++ b/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java @@ -37,15 +37,12 @@ public class CSExceptionErrorCode { try { ExceptionErrorCodeMap = new HashMap(); ExceptionErrorCodeMap.put("com.cloud.utils.exception.CloudRuntimeException", 4250); - ExceptionErrorCodeMap.put("com.cloud.utils.exception.ExceptionUtil", 4255); ExceptionErrorCodeMap.put("com.cloud.utils.exception.ExecutionException", 4260); ExceptionErrorCodeMap.put("com.cloud.utils.exception.HypervisorVersionChangedException", 4265); - ExceptionErrorCodeMap.put("com.cloud.utils.exception.RuntimeCloudException", 4270); ExceptionErrorCodeMap.put("com.cloud.exception.CloudException", 4275); ExceptionErrorCodeMap.put("com.cloud.exception.AccountLimitException", 4280); ExceptionErrorCodeMap.put("com.cloud.exception.AgentUnavailableException", 4285); ExceptionErrorCodeMap.put("com.cloud.exception.CloudAuthenticationException", 4290); - ExceptionErrorCodeMap.put("com.cloud.exception.CloudExecutionException", 4295); ExceptionErrorCodeMap.put("com.cloud.exception.ConcurrentOperationException", 4300); ExceptionErrorCodeMap.put("com.cloud.exception.ConflictingNetworkSettingsException", 4305); ExceptionErrorCodeMap.put("com.cloud.exception.DiscoveredWithErrorException", 4310); @@ -66,35 +63,6 @@ public class CSExceptionErrorCode { ExceptionErrorCodeMap.put("com.cloud.exception.StorageUnavailableException", 4385); ExceptionErrorCodeMap.put("com.cloud.exception.UnsupportedServiceException", 4390); ExceptionErrorCodeMap.put("com.cloud.exception.VirtualMachineMigrationException", 4395); - - ExceptionErrorCodeMap.put("com.cloud.exception.AccountLimitException", 4400); - ExceptionErrorCodeMap.put("com.cloud.exception.AgentUnavailableException", 4405); - ExceptionErrorCodeMap.put("com.cloud.exception.CloudAuthenticationException", 4410); - ExceptionErrorCodeMap.put("com.cloud.exception.CloudException", 4415); - ExceptionErrorCodeMap.put("com.cloud.exception.CloudExecutionException", 4420); - ExceptionErrorCodeMap.put("com.cloud.exception.ConcurrentOperationException", 4425); - ExceptionErrorCodeMap.put("com.cloud.exception.ConflictingNetworkSettingsException", 4430); - ExceptionErrorCodeMap.put("com.cloud.exception.ConnectionException", 4435); - ExceptionErrorCodeMap.put("com.cloud.exception.DiscoveredWithErrorException", 4440); - ExceptionErrorCodeMap.put("com.cloud.exception.DiscoveryException", 4445); - ExceptionErrorCodeMap.put("com.cloud.exception.HAStateException", 4450); - ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientAddressCapacityException", 4455); - ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientCapacityException", 4460); - ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientNetworkCapacityException", 4465); - ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientServerCapacityException", 4470); - ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientStorageCapacityException", 4475); - ExceptionErrorCodeMap.put("com.cloud.exception.InsufficientVirtualNetworkCapcityException", 4480); - ExceptionErrorCodeMap.put("com.cloud.exception.InternalErrorException", 4485); - ExceptionErrorCodeMap.put("com.cloud.exception.InvalidParameterValueException", 4490); - ExceptionErrorCodeMap.put("com.cloud.exception.ManagementServerException", 4495); - ExceptionErrorCodeMap.put("com.cloud.exception.NetworkRuleConflictException", 4500); - ExceptionErrorCodeMap.put("com.cloud.exception.PermissionDeniedException", 4505); - ExceptionErrorCodeMap.put("com.cloud.exception.ResourceAllocationException", 4510); - ExceptionErrorCodeMap.put("com.cloud.exception.ResourceInUseException", 4515); - ExceptionErrorCodeMap.put("com.cloud.exception.ResourceUnavailableException", 4520); - ExceptionErrorCodeMap.put("com.cloud.exception.StorageUnavailableException", 4525); - ExceptionErrorCodeMap.put("com.cloud.exception.UnsupportedServiceException", 4530); - ExceptionErrorCodeMap.put("com.cloud.exception.VirtualMachineMigrationException", 4535); ExceptionErrorCodeMap.put("com.cloud.async.AsyncCommandQueued", 4540); // Have a special error code for ServerApiException when it is