Piotr Kliczewski has uploaded a new change for review. Change subject: core: setupNetworks not able to configure brige ......................................................................
core: setupNetworks not able to configure brige For 2 calls we use ThreadPoolUtil. It was used to provide async network call for xmlrpc. Jsonrpc is async so from its prespective it makes no sense to use it. In order to keep the communication interface unchanged we need to returned Future. The future checked whether the call was executed not whether the response arrived. This patch makes sure that we wait for response and expose this information correctly. Bug-Url: https://bugzilla.redhat.com/1136876 Change-Id: I70bfa5d7f154a13f7d52f7710eb109de1da0b82c Signed-off-by: pkliczewski <piotr.kliczew...@gmail.com> --- M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/FutureMap.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java 2 files changed, 92 insertions(+), 22 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/69/32469/1 diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/FutureMap.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/FutureMap.java index 248f79e..3a236ef 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/FutureMap.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/FutureMap.java @@ -6,6 +6,8 @@ import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -29,6 +31,7 @@ public class FutureMap implements Map<String, Object> { private final static String STATUS = "status"; private final static String DEFAULT_KEY = "info"; + private final static long DEFAULT_RESPONSE_WAIT = 1; private static Log log = LogFactory.getLog(FutureMap.class); private final Lock lock = new ReentrantLock(); private Future<JsonRpcResponse> response; @@ -63,26 +66,51 @@ /** * Whenever any method is executed to obtain value of response during the first invocation it gets real response * from the <code>Future</code> and decompose it to object of provided type and structure. + * + * This method blocks waiting on response or error. */ private void lazyEval() { try (LockWrapper wrapper = new LockWrapper(this.lock)) { if (this.responseMap.isEmpty()) { - ResponseDecomposer decomposer; try { - decomposer = new ResponseDecomposer(this.response.get()); - if (decomposer.isError()) { - this.responseMap = decomposer.decomposeError(); - } else if (Object[].class.equals(clazz) && this.subtypeKey != null && !this.subtypeKey.trim().isEmpty() - && this.subTypeClazz != null) { - Object[] array = (Object[]) decomposer.decomposeResponse(this.clazz); - updateResponse(decomposer.decomposeTypedArray(array, this.subTypeClazz, subtypeKey)); - } else { - updateResponse(decomposer.decomposeResponse(this.clazz)); - } - checkAndUpdateStatus(); + populate(this.response.get()); } catch (InterruptedException | ExecutionException e) { log.error("Exception occured during response decomposition", e); throw new IllegalStateException(e); + } + } + } + } + + private void populate(JsonRpcResponse response) { + ResponseDecomposer decomposer = new ResponseDecomposer(response); + if (decomposer.isError()) { + this.responseMap = decomposer.decomposeError(); + } else if (Object[].class.equals(clazz) && this.subtypeKey != null && !this.subtypeKey.trim().isEmpty() + && this.subTypeClazz != null) { + Object[] array = (Object[]) decomposer.decomposeResponse(this.clazz); + updateResponse(decomposer.decomposeTypedArray(array, this.subTypeClazz, subtypeKey)); + } else { + updateResponse(decomposer.decomposeResponse(this.clazz)); + } + checkAndUpdateStatus(); + } + + /** + * Whenever any method is executed to obtain value of response during the first invocation it gets real response + * from the <code>Future</code> and decompose it to object of provided type and structure. + * + * This method waits for a response or error for specified amount of time. + * + * @param wait - time in seconds how long we want to wait for response. + */ + private void lazyEval(long wait) { + try (LockWrapper wrapper = new LockWrapper(this.lock)) { + if (this.responseMap.isEmpty()) { + try { + populate(this.response.get(wait, TimeUnit.SECONDS)); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + log.debug("Response not arrived yet"); } } } @@ -125,6 +153,11 @@ return this.responseMap.isEmpty(); } + public boolean isDone() { + lazyEval(DEFAULT_RESPONSE_WAIT); + return !this.responseMap.isEmpty(); + } + @Override public Set<String> keySet() { lazyEval(); diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java index bbba12b..0d9d80a 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java @@ -382,6 +382,29 @@ return new StatusOnlyReturnForXmlRpc(response); } + class FutureCallable implements Callable<Map<String, Object>> { + private Callable<Map<String, Object>> callable; + + private FutureMap map; + + public FutureCallable(Callable<Map<String, Object>> callable) { + this.callable = callable; + } + + @Override + public Map<String, Object> call() throws Exception { + this.map = (FutureMap) this.callable.call(); + return this.map; + } + + public boolean isDone() { + if (this.map == null) { + return false; + } + return this.map.isDone(); + } + } + @SuppressWarnings("rawtypes") @Override public Future<Map<String, Object>> setupNetworks(Map networks, Map bonding, Map options) { @@ -390,14 +413,20 @@ .withParameter("bondings", bonding) .withParameter("options", options) .build(); - FutureTask<Map<String, Object>> future = - new FutureTask<Map<String, Object>>(new Callable<Map<String, Object>>() { + final FutureCallable callable = new FutureCallable(new Callable<Map<String, Object>>() { + + @Override + public Map<String, Object> call() throws Exception { + return new FutureMap(client, request).withResponseKey("status"); + } + }); + FutureTask<Map<String, Object>> future = new FutureTask<Map<String, Object>>(callable) { @Override - public Map<String, Object> call() throws Exception { - return new FutureMap(client, request).withResponseKey("status"); + public boolean isDone() { + return callable.isDone(); } - }); + }; ThreadPoolUtil.execute(future); return future; } @@ -863,14 +892,22 @@ @Override public FutureTask<Map<String, Object>> poll() { final JsonRpcRequest request = new RequestBuilder("Host.ping").build(); - FutureTask<Map<String, Object>> future = - new FutureTask<Map<String, Object>>(new Callable<Map<String, Object>>() { + final FutureCallable callable = new FutureCallable(new Callable<Map<String, Object>>() { + + @Override + public Map<String, Object> call() throws Exception { + return new FutureMap(client, request); + } + }); + + FutureTask<Map<String, Object>> future = new FutureTask<Map<String, Object>>(callable) { @Override - public Map<String, Object> call() throws Exception { - return new FutureMap(client, request); + public boolean isDone() { + return callable.isDone(); } - }); + }; + ThreadPoolUtil.execute(future); return future; } -- To view, visit http://gerrit.ovirt.org/32469 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I70bfa5d7f154a13f7d52f7710eb109de1da0b82c Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Piotr Kliczewski <piotr.kliczew...@gmail.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches