Liron Ar has uploaded a new change for review.

Change subject: uploadstream
......................................................................

uploadstream

Change-Id: I1388a59361a6d38d6f3c04aaf9e09c08757f2ec3
Signed-off-by: Liron Aravot <[email protected]>
---
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/UploadStreamVDSCommand.java
1 file changed, 57 insertions(+), 32 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/28/23528/1

diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/UploadStreamVDSCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/UploadStreamVDSCommand.java
index 78660ce..c54618d 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/UploadStreamVDSCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/UploadStreamVDSCommand.java
@@ -1,21 +1,20 @@
 package org.ovirt.engine.core.vdsbroker.irsbroker;
 
+import java.net.URL;
 import java.util.HashMap;
 
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
 import org.apache.commons.httpclient.methods.PutMethod;
 import org.codehaus.jackson.map.ObjectMapper;
-import org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo;
-import org.ovirt.engine.core.common.asynctasks.AsyncTaskType;
 import org.ovirt.engine.core.common.businessentities.VdsStatic;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
-import org.ovirt.engine.core.common.constants.StorageConstants;
+import org.ovirt.engine.core.common.utils.Pair;
 import 
org.ovirt.engine.core.common.vdscommands.UploadStreamVDSCommandParameters;
-import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.utils.lock.EngineLock;
 import org.ovirt.engine.core.utils.log.Log;
@@ -23,6 +22,7 @@
 import org.ovirt.engine.core.vdsbroker.ResourceManager;
 import org.ovirt.engine.core.vdsbroker.VdsManager;
 import org.ovirt.engine.core.vdsbroker.vdsbroker.StatusOnlyReturnForXmlRpc;
+import org.ovirt.engine.core.vdsbroker.vdsbroker.VDSErrorException;
 import org.ovirt.engine.core.vdsbroker.vdsbroker.VdsBrokerCommand;
 import org.ovirt.engine.core.vdsbroker.vdsbroker.VdsServerWrapper;
 import org.ovirt.engine.core.vdsbroker.xmlrpc.XmlRpcUtils;
@@ -52,15 +52,18 @@
         HttpClient httpclient = ((VdsServerWrapper) 
manager.getVdsProxy()).getHttpClient();
         VdsStatic vdsStatic =
                 
DbFacade.getInstance().getVdsStaticDao().get(manager.getVdsId());
+
+        Pair<String, URL> urlInfo = 
XmlRpcUtils.getConnectionUrl(vdsStatic.getHostName(),
+                vdsStatic.getPort(),
+                "",
+                Config.<Boolean> 
getValue(ConfigValues.EncryptHostCommunication));
+
+        if (urlInfo == null) {
+            throwVdsErrorException("UploadStreamVDSCommand - failed get host 
url");
+        }
+
         PutMethod putMethod =
-                new 
PutMethod(XmlRpcUtils.getConnectionUrl(vdsStatic.getHostName(),
-                        vdsStatic.getPort(),
-                        "",
-                        Config.<Boolean> 
getValue(ConfigValues.EncryptHostCommunication)).getFirst());
-
-        putMethod.getParams().setParameter("http.socket.timeout", 
StorageConstants.UPLOAD_SOCKET_TIMEOUT);
-
-        RuntimeException executionException = null;
+                new PutMethod(urlInfo.getFirst());
         try {
             InputStreamRequestEntity inputStreamRequestEntity = null;
             if (getParameters().getStreamLength() != null) {
@@ -82,48 +85,70 @@
             putMethod.setRequestHeader("X-Storage-Domain-Id", 
getParameters().getStorageDomainId().toString());
             putMethod.setRequestHeader("X-Image-Id", 
getParameters().getImageGroupId().toString());
             putMethod.setRequestHeader("X-Volume-Id", 
getParameters().getImageId().toString());
-            httpclient.executeMethod(putMethod);
 
-            processResponseHeaderValue(putMethod, "Content-type", 
"application/json");
-            status = new StatusOnlyReturnForXmlRpc(
-                    new 
ObjectMapper().readValue(putMethod.getResponseBodyAsString(), HashMap.class));
+            int responseCode = -1;
 
-            String createdTaskId = processResponseHeaderValue(putMethod, 
"X-Task-Id", null);
-
-            if (createdTaskId != null) {
-                Guid createdTask = Guid.createGuidFromString(createdTaskId);
-                getVDSReturnValue().setCreationInfo(
-                        new AsyncTaskCreationInfo(createdTask, 
AsyncTaskType.copyImage, getParameters()
-                                .getStoragePoolId()));
+            try {
+                // need to look into socket write timeout here.
+                responseCode = httpclient.executeMethod(putMethod);
+            } catch (Exception e) {
+                throwVdsErrorException("UploadStreamVDSCommand - failed to 
execute request");
             }
 
+            if (responseCode != HttpStatus.SC_OK) {
+                throwVdsErrorException("UploadStreamVDSCommand - upload failed 
with response code " + responseCode);
+            }
+
+            processResponseHeaderValue(putMethod, "Content-type", 
"application/json");
+
+            String response = null;
+            try {
+                response = putMethod.getResponseBodyAsString();
+            } catch (Exception e) {
+                throwVdsErrorException("UploadStreamVDSCommand - failed to 
getResponseBody");
+            }
+
+            try {
+                status = new StatusOnlyReturnForXmlRpc(
+                    new ObjectMapper().readValue(response, HashMap.class));
+            } catch (Exception e){
+                throwVdsErrorException("UploadStreamVDSCommand - failed to 
parse response " + response);
+            }
+
+//            String createdTaskId = processResponseHeaderValue(putMethod, 
"X-Task-Id", null);
+//
+//            if (createdTaskId != null) {
+//                Guid createdTask = Guid.createGuidFromString(createdTaskId);
+//                getVDSReturnValue().setCreationInfo(
+//                        new AsyncTaskCreationInfo(createdTask, 
AsyncTaskType.copyImage, getParameters()
+//                                .getStoragePoolId()));
+//            }
+
             getVDSReturnValue().setSucceeded(true);
-        } catch (Exception e) {
-            executionException = new RuntimeException(e);
         } finally {
             try {
                 putMethod.releaseConnection();
-            } catch (Exception releaseException) {
+            } catch (RuntimeException releaseException) {
                 log.error("failed when attempting to release connection", 
releaseException);
-                if (executionException != null) {
-                    throw executionException;
-                }
-                throw releaseException;
             }
         }
 
         proceedProxyReturnValue();
     }
 
+    private void throwVdsErrorException(String message) {
+        throw new VDSErrorException(message);
+    }
+
     private String processResponseHeaderValue(HttpMethodBase method, String 
headerName, String expectedValue) {
         Header header = method.getResponseHeader(headerName);
         if (header == null) {
-            throw new RuntimeException("UploadStreamVDSCommand - response was 
missing the following header: "
+            throwVdsErrorException("UploadStreamVDSCommand - response was 
missing the following header: "
                     + headerName);
         }
 
         if (expectedValue != null && !expectedValue.equals(header.getValue())) 
{
-            throw new RuntimeException("UploadStreamVDSCommand - response 
header value unexpected for header: "
+            throwVdsErrorException("UploadStreamVDSCommand - response header 
value unexpected for header: "
                     + headerName);
         }
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1388a59361a6d38d6f3c04aaf9e09c08757f2ec3
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Liron Ar <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to