Mike Kolesnik has uploaded a new change for review.

Change subject: core: Added provider specific errors
......................................................................

core: Added provider specific errors

Added errors to specify that communicating with the external provider
failed.
Where possible, a more specific error is used.

Change-Id: Ia75e9653d98b8e2682f3dc0e82165d16c6af0c1b
Signed-off-by: Mike Kolesnik <mkole...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/quantum/QuantumProviderProxy.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllErrors.java
M backend/manager/modules/dal/src/main/resources/bundles/VdsmErrors.properties
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/VdsmErrors.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/VdsmErrors.properties
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/VdsmErrors.properties
6 files changed, 57 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/01/12401/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/quantum/QuantumProviderProxy.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/quantum/QuantumProviderProxy.java
index 933ec01..2a10a6f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/quantum/QuantumProviderProxy.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/quantum/QuantumProviderProxy.java
@@ -56,28 +56,26 @@
         }
 
         try {
-            PostMethod method = new PostMethod(providerDetails.getUrl() + 
"/networks");
-            method.setRequestEntity(
-                    new 
StringRequestEntity(objectMapper.writeValueAsString(quantumNetwork), 
"application/json", null));
+            PostMethod method = createPostMethod("/networks", quantumNetwork);
             httpClient.executeMethod(method);
             
objectMapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
             return new Guid(objectMapper.readValue(method.getResponseBody(), 
QuantumNetwork.class).getId());
         } catch (IOException e) {
-            throw new VdcBLLException(VdcBllErrors.ENGINE, new 
RuntimeException(e));
+            throw new VdcBLLException(VdcBllErrors.PROVIDER_FAILURE, new 
RuntimeException(e));
         }
     }
 
     @Override
     public List<Network> getAll() {
-        HttpMethod method = new GetMethod(providerDetails.getUrl() + 
"/networks");
         try {
+            HttpMethod method = createGetMethod("/networks");
             httpClient.executeMethod(method);
             
objectMapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, false);
             QuantumNetwork[] networks =
                     objectMapper.readValue(method.getResponseBody(), 
QuantumNetworksList.class).getNetworks();
             return map(Arrays.asList(networks));
         } catch (IOException e) {
-            throw new VdcBLLException(VdcBllErrors.ENGINE, new 
RuntimeException(e));
+            throw new VdcBLLException(VdcBllErrors.PROVIDER_FAILURE, new 
RuntimeException(e));
         }
     }
 
@@ -113,19 +111,17 @@
             port.setDeviceOwner(DEVICE_OWNER);
             port.setDeviceId(nic.getId().getUuid());
 
-            PostMethod method = new PostMethod(providerDetails.getUrl() + 
"/ports");
-            method.setRequestEntity(
-                    new 
StringRequestEntity(objectMapper.writeValueAsString(port), "application/json", 
null));
+            PostMethod method = createPostMethod("/ports", port);
             httpClient.executeMethod(method);
             
objectMapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
             return objectMapper.readValue(method.getResponseBody(), 
QuantumPort.class).getId().toString();
         } catch (IOException e) {
-            throw new VdcBLLException(VdcBllErrors.ENGINE, new 
RuntimeException(e));
+            throw new VdcBLLException(VdcBllErrors.PROVIDER_FAILURE, new 
RuntimeException(e));
         }
     }
 
     private QuantumNetwork getQuantumNetwork(Network network) throws 
IOException {
-        HttpMethod method = new GetMethod(providerDetails.getUrl() + 
"/networks/" + network.getId());
+        HttpMethod method = createGetMethod("/networks/" + network.getId());
         httpClient.executeMethod(method);
         
objectMapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
         return objectMapper.readValue(method.getResponseBody(), 
QuantumNetwork.class);
@@ -137,17 +133,16 @@
             QuantumPort[] ports = getQuantumPorts();
             for (QuantumPort port : ports) {
                 if (DEVICE_OWNER.equals(port.getDeviceOwner()) && 
nic.getId().getUuid().equals(port.getDeviceId())) {
-                    HttpMethod method = new 
DeleteMethod(providerDetails.getUrl() + "/ports/" + port.getId());
-                    httpClient.executeMethod(method);
+                    httpClient.executeMethod(createDeleteMethod("/ports/" + 
port.getId()));
                 }
             }
         } catch (IOException e) {
-            throw new VdcBLLException(VdcBllErrors.ENGINE, new 
RuntimeException(e));
+            throw new VdcBLLException(VdcBllErrors.PROVIDER_FAILURE, new 
RuntimeException(e));
         }
     }
 
     private QuantumPort[] getQuantumPorts() throws IOException {
-        HttpMethod method = new GetMethod(providerDetails.getUrl() + "/ports");
+        HttpMethod method = createGetMethod("/ports");
         httpClient.executeMethod(method);
         
objectMapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, false);
         QuantumPort[] ports = objectMapper.readValue(method.getResponseBody(), 
QuantumPortsList.class).getPorts();
@@ -162,4 +157,39 @@
     public void testConnection() {
         getAll();
     }
+
+    private HttpMethod createGetMethod(String resource) {
+        try {
+            return new GetMethod(providerDetails.getUrl() + resource);
+        } catch (IllegalArgumentException e) {
+            throw new VdcBLLException(VdcBllErrors.INVALID_PROVIDER_URL);
+        } catch (IllegalStateException e) {
+            throw new VdcBLLException(VdcBllErrors.INVALID_PROVIDER_URL);
+        }
+    }
+
+    private PostMethod createPostMethod(String resource, Object value) {
+        try {
+            PostMethod method = new PostMethod(providerDetails.getUrl() + 
resource);
+            method.setRequestEntity(
+                    new 
StringRequestEntity(objectMapper.writeValueAsString(value), "application/json", 
null));
+            return method;
+        } catch (IllegalArgumentException e) {
+            throw new VdcBLLException(VdcBllErrors.INVALID_PROVIDER_URL);
+        } catch (IllegalStateException e) {
+            throw new VdcBLLException(VdcBllErrors.INVALID_PROVIDER_URL);
+        } catch (IOException e) {
+            throw new VdcBLLException(VdcBllErrors.PROVIDER_FAILURE, new 
RuntimeException(e));
+        }
+    }
+
+    private HttpMethod createDeleteMethod(String resource) {
+        try {
+            return new DeleteMethod(providerDetails.getUrl() + resource);
+        } catch (IllegalArgumentException e) {
+            throw new VdcBLLException(VdcBllErrors.INVALID_PROVIDER_URL);
+        } catch (IllegalStateException e) {
+            throw new VdcBLLException(VdcBllErrors.INVALID_PROVIDER_URL);
+        }
+    }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllErrors.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllErrors.java
index 6b80bcb..2924266 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllErrors.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllErrors.java
@@ -388,6 +388,8 @@
     NO_PARAMETERS_FOR_TASK(5026),
     HOST_ALREADY_EXISTS(5027),
     NO_ACTIVE_ISO_DOMAIN_IN_DATA_CENTER(5028),
+    PROVIDER_FAILURE(5050),
+    INVALID_PROVIDER_URL(5051),
     // Gluster errors
     NO_UP_SERVER_FOUND(7000),
     // error to indicate backend does not recognize the session
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/VdsmErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/VdsmErrors.properties
index bc9e432..9831cf0 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/VdsmErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/VdsmErrors.properties
@@ -346,6 +346,8 @@
 DEVICE_BLOCK_SIZE_NOT_SUPPORTED=Volume Group block size error, please check 
your Volume Group configuration, Supported block size is 512 bytes.
 HOST_ALREADY_EXISTS=Cannot add Host. Host with same characteristics already 
exists.
 NO_ACTIVE_ISO_DOMAIN_IN_DATA_CENTER=There is no active ISO Domain in Data 
Center.
+PROVIDER_FAILURE=Failed to communicate with the external provider.
+INVALID_PROVIDER_URL=The provider URL is malformed, please check your provider 
configuration and make sure the URL is valid.
 MIGRATION_DEST_INVALID_HOSTNAME=Migration destination has an invalid hostname
 MIGRATION_CANCEL_ERROR=Migration not in progress
 MIGRATION_CANCEL_ERROR_NO_VM=Cancel migration has failed. Please try again in 
a few moments and track the VM's event log for details.
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/VdsmErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/VdsmErrors.java
index 0493ee8..9a4d017 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/VdsmErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/VdsmErrors.java
@@ -647,6 +647,10 @@
 
     String NO_ACTIVE_ISO_DOMAIN_IN_DATA_CENTER();
 
+    String PROVIDER_FAILURE();
+
+    String INVALID_PROVIDER_URL();
+
     String MIGRATION_DEST_INVALID_HOSTNAME();
 
     String MIGRATION_CANCEL_ERROR();
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/VdsmErrors.properties
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/VdsmErrors.properties
index beaf145..b08d660 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/VdsmErrors.properties
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/VdsmErrors.properties
@@ -320,6 +320,8 @@
 DEVICE_BLOCK_SIZE_NOT_SUPPORTED=Volume Group block size error, please check 
your Volume Group configuration, Supported block size is 512 bytes.
 HOST_ALREADY_EXISTS=Cannot add Host. Host with same characteristics already 
exists.
 NO_ACTIVE_ISO_DOMAIN_IN_DATA_CENTER=There is no active ISO Domain in Data 
Center.
+PROVIDER_FAILURE=Failed to communicate with the external provider.
+INVALID_PROVIDER_URL=The provider URL is malformed, please check your provider 
configuration and make sure the URL is valid.
 MIGRATION_DEST_INVALID_HOSTNAME=Migration destination has an invalid hostname
 MIGRATION_CANCEL_ERROR=Migration not in progress
 DB=Database error.
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/VdsmErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/VdsmErrors.properties
index beaf145..b08d660 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/VdsmErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/VdsmErrors.properties
@@ -320,6 +320,8 @@
 DEVICE_BLOCK_SIZE_NOT_SUPPORTED=Volume Group block size error, please check 
your Volume Group configuration, Supported block size is 512 bytes.
 HOST_ALREADY_EXISTS=Cannot add Host. Host with same characteristics already 
exists.
 NO_ACTIVE_ISO_DOMAIN_IN_DATA_CENTER=There is no active ISO Domain in Data 
Center.
+PROVIDER_FAILURE=Failed to communicate with the external provider.
+INVALID_PROVIDER_URL=The provider URL is malformed, please check your provider 
configuration and make sure the URL is valid.
 MIGRATION_DEST_INVALID_HOSTNAME=Migration destination has an invalid hostname
 MIGRATION_CANCEL_ERROR=Migration not in progress
 DB=Database error.


--
To view, visit http://gerrit.ovirt.org/12401
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia75e9653d98b8e2682f3dc0e82165d16c6af0c1b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Mike Kolesnik <mkole...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to