aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpmcmahan2012-10-15 13:16:09 (EDT)
committerpmcmahan2012-10-15 13:16:09 (EDT)
commit0f208256e52eaaad89c867534143066577b0241e (patch)
tree81351b164b47855a50092594e29cc9b5b7473819
parent87692b63758729614837e713c9e421c370883dfc (diff)
downloadorg.eclipse.lyo.client-0f208256e52eaaad89c867534143066577b0241e.zip
org.eclipse.lyo.client-0f208256e52eaaad89c867534143066577b0241e.tar.gz
org.eclipse.lyo.client-0f208256e52eaaad89c867534143066577b0241e.tar.bz2
Bug 391931 send status updates during automationrefs/changes/19/8219/1
-rw-r--r--org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/AutomationAdapter.java141
-rw-r--r--org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/IConstants.java6
-rw-r--r--org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/Message.java78
-rw-r--r--org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/RQMAutomationSample.java28
-rw-r--r--org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/StatusResponse.java118
5 files changed, 347 insertions, 24 deletions
diff --git a/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/AutomationAdapter.java b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/AutomationAdapter.java
index 9f1b3fd..b7f4644 100644
--- a/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/AutomationAdapter.java
+++ b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/AutomationAdapter.java
@@ -243,7 +243,7 @@ public class AutomationAdapter extends AbstractResource implements IConstants {
@OslcDescription("Type (reference: Dublin Core) of adapter.")
@OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "type")
@OslcTitle("Type")
- @OslcValueType(ValueType.XMLLiteral)
+ @OslcValueType(ValueType.String)
public String getType() {
return type;
}
@@ -254,7 +254,7 @@ public class AutomationAdapter extends AbstractResource implements IConstants {
@OslcPropertyDefinition(NAMESPACE_URI_JAZZ_QM + "hostname")
@OslcTitle("Hostname")
- @OslcValueType(ValueType.XMLLiteral)
+ @OslcValueType(ValueType.String)
public String getHostname() {
return hostname;
}
@@ -265,7 +265,7 @@ public class AutomationAdapter extends AbstractResource implements IConstants {
@OslcPropertyDefinition(NAMESPACE_URI_JAZZ_QM + "ipAddress")
@OslcTitle("IP Address")
- @OslcValueType(ValueType.XMLLiteral)
+ @OslcValueType(ValueType.String)
public String getIpAddress() {
return ipAddress;
}
@@ -287,7 +287,7 @@ public class AutomationAdapter extends AbstractResource implements IConstants {
@OslcPropertyDefinition(NAMESPACE_URI_JAZZ_QM + "macAddress")
@OslcTitle("MAC Address")
- @OslcValueType(ValueType.XMLLiteral)
+ @OslcValueType(ValueType.String)
public String getMacAddress() {
return macAddress;
}
@@ -298,7 +298,7 @@ public class AutomationAdapter extends AbstractResource implements IConstants {
@OslcPropertyDefinition(NAMESPACE_URI_JAZZ_QM + "fullyQualifiedDomainName")
@OslcTitle("Fully Qualified Domain Name")
- @OslcValueType(ValueType.XMLLiteral)
+ @OslcValueType(ValueType.String)
public String getFullyQualifiedDomainName() {
return fullyQualifiedDomainName;
}
@@ -367,7 +367,7 @@ public class AutomationAdapter extends AbstractResource implements IConstants {
@OslcDescription("Identifier (reference: Dublin Core) for the adapter.")
@OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "identifier")
@OslcTitle("Identifier")
- @OslcValueType(ValueType.XMLLiteral)
+ @OslcValueType(ValueType.String)
public String getIdentifier() {
return identifier;
}
@@ -591,6 +591,8 @@ public class AutomationAdapter extends AbstractResource implements IConstants {
request.setStates(new URI[] { URI.create(
AutomationConstants.STATE_COMPLETE) });
+ request.getExtendedProperties().remove(PROPERTY_RQM_PROGRESS);
+
request.getExtendedProperties().put(PROPERTY_RQM_PROGRESS,
new Integer(100));
@@ -1178,22 +1180,22 @@ public class AutomationAdapter extends AbstractResource implements IConstants {
}
/**
- * Set the current progress percentage of the Automation. If the provided
- * value is greater than 99 then it is adjusted down to 99 since the
- * progress should not reach 100 until the {@link IAutomationRequestHandler}
- * has finished processing the request and returned control back to this
- * Adapter.
+ * Send the current progress (percentage) of the Automation Request. If the
+ * provided value is greater than 99 then it is adjusted down to 99 since
+ * the progress should not reach 100 until the
+ * {@link IAutomationRequestHandler} has finished processing the request and
+ * returned control back to this Adapter.
*
* Before calling this method the adapter needs to be logged in and
* registered with the automation service provider.
*
- * @param request
* @param i
* An integer less than 100
+ * @param request
* @throws URISyntaxException
* @throws AutomationException
*/
- public void setProgress(AutomationRequest request, int i)
+ public void sendProgressForRequest(int i, AutomationRequest request)
throws URISyntaxException, AutomationException {
if (!isRegistered) {
@@ -1208,17 +1210,70 @@ public class AutomationAdapter extends AbstractResource implements IConstants {
i = 99;
}
- request.getExtendedProperties().put(PROPERTY_RQM_PROGRESS,
+ AutomationRequest requestCopy = new AutomationRequest(request.getAbout());
+
+ requestCopy.getExtendedProperties().put(PROPERTY_RQM_PROGRESS,
new Integer(i));
- URI updateUri = appendOslcProperties(request.getAbout(),
+ URI updateUri = appendOslcProperties(requestCopy.getAbout(),
"rqm_qm:progress");
ClientResponse response;
synchronized (client) {
- response = client.updateResource(updateUri.toString(), request,
+ response = client.updateResource(updateUri.toString(), requestCopy,
+ OslcMediaType.APPLICATION_RDF_XML);
+
+ response.consumeContent();
+
+ }
+
+ if (response.getStatusCode() != HttpStatus.SC_OK) {
+
+ throw new AutomationException(
+ "Failed to update AutomationResult at "
+ + updateUri.toString() + ". "
+ + response.getStatusCode() + ": "
+ + response.getMessage());
+
+ }
+
+ }
+
+ /**
+ * Send a status for the Automation Request. Before calling this method the
+ * adapter needs to be logged in and registered with the automation service
+ * provider.
+ *
+ * @param statusResponse
+ * @param request
+ * @throws URISyntaxException
+ * @throws AutomationException
+ */
+ public void sendStatusForRequest(StatusResponse statusResponse,
+ AutomationRequest request) throws AutomationException {
+
+ if (!isRegistered) {
+
+ throw new AutomationException(
+ "Adapter is not registered with the Automation Service Provider");
+
+ }
+
+ AutomationRequest requestCopy = new AutomationRequest(request.getAbout());
+
+ requestCopy.getExtendedProperties().put(PROPERTY_RQM_STATUS_RESPONSE,
+ statusResponse);
+
+ URI updateUri = appendOslcProperties(requestCopy.getAbout(),
+ "rqm_qm:statusResponse");
+
+ ClientResponse response;
+
+ synchronized (client) {
+
+ response = client.updateResource(updateUri.toString(), requestCopy,
OslcMediaType.APPLICATION_RDF_XML);
response.consumeContent();
@@ -1234,8 +1289,60 @@ public class AutomationAdapter extends AbstractResource implements IConstants {
+ response.getMessage());
}
+
+ }
+
+ /**
+ * Send a message update to the Automation Request. Before calling this
+ * method the adapter needs to be logged in and registered with the
+ * automation service provider.
+ *
+ * @param message
+ * @param request
+ * @throws URISyntaxException
+ * @throws AutomationException
+ */
+ public void sendMessageForRequest(Message message, AutomationRequest request)
+ throws AutomationException {
+
+ if (!isRegistered) {
+
+ throw new AutomationException(
+ "Adapter is not registered with the Automation Service Provider");
+
+ }
+
+ AutomationRequest requestCopy = new AutomationRequest(request.getAbout());
+ requestCopy.getExtendedProperties().put(PROPERTY_RQM_MESSAGE,
+ message);
+
+ URI updateUri = appendOslcProperties(requestCopy.getAbout(),
+ "rqm_qm:message");
+
+ ClientResponse response;
+
+ synchronized (client) {
+
+ response = client.updateResource(updateUri.toString(), requestCopy,
+ OslcMediaType.APPLICATION_RDF_XML);
+
+ response.consumeContent();
+
+ }
+
+ if (response.getStatusCode() != HttpStatus.SC_OK) {
+
+ throw new AutomationException(
+ "Failed to update AutomationResult at "
+ + updateUri.toString() + ". "
+ + response.getStatusCode() + ": "
+ + response.getMessage());
+
+ }
+
}
+
/**
* Cancel an Automation Request by updating its desiredState property to
@@ -1325,4 +1432,4 @@ public class AutomationAdapter extends AbstractResource implements IConstants {
}
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/IConstants.java b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/IConstants.java
index 0a3ebc7..02c06b8 100644
--- a/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/IConstants.java
+++ b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/IConstants.java
@@ -26,6 +26,8 @@ public interface IConstants {
String NAMESPACE_URI_DC_ELEMENTS = "http://purl.org/dc/elements/1.1/"; //$NON-NLS-1$
String TYPE_AUTOMATION_ADAPTER = NAMESPACE_URI_JAZZ_QM + "AutomationAdapter";
+ String TYPE_STATUS_RESPONSE = NAMESPACE_URI_JAZZ_QM + "StatusResponse";
+ String TYPE_MESSAGE = NAMESPACE_URI_JAZZ_QM + "Message";
QName PROPERTY_DC_RELATION = new QName(OSLCConstants.DC, "relation");
@@ -45,5 +47,7 @@ public interface IConstants {
QName PROPERTY_RQM_END_TIME = new QName(IConstants.NAMESPACE_URI_JAZZ_QM, "endTime");
QName PROPERTY_RQM_ATTACHMENT = new QName(IConstants.NAMESPACE_URI_JAZZ_QM, "attachment");
QName PROPERTY_RQM_EXECUTED_ON_MACHINE = new QName(IConstants.NAMESPACE_URI_JAZZ_QM, "executedOnMachine");
+ QName PROPERTY_RQM_STATUS_RESPONSE = new QName(IConstants.NAMESPACE_URI_JAZZ_QM, "statusResponse");
+ QName PROPERTY_RQM_MESSAGE = new QName(IConstants.NAMESPACE_URI_JAZZ_QM, "message");
-}
+} \ No newline at end of file
diff --git a/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/Message.java b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/Message.java
new file mode 100644
index 0000000..fc009e7
--- /dev/null
+++ b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/Message.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Paul McMahan <pmcmahan@us.ibm.com> - initial implementation
+ *******************************************************************************/
+package org.eclipse.lyo.client.oslc.samples.automation;
+
+import org.eclipse.lyo.oslc4j.core.annotation.OslcDescription;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcNamespace;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcOccurs;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcPropertyDefinition;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcResourceShape;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcTitle;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcValueType;
+import org.eclipse.lyo.oslc4j.core.model.AbstractResource;
+import org.eclipse.lyo.oslc4j.core.model.Occurs;
+import org.eclipse.lyo.oslc4j.core.model.ValueType;
+
+@OslcResourceShape(title = "Message Resource Shape", describes = IConstants.TYPE_MESSAGE)
+@OslcNamespace(IConstants.NAMESPACE_URI_JAZZ_QM)
+public class Message extends AbstractResource implements IConstants {
+
+ private String name;
+ private String value;
+
+ /**
+ * Default Constructor
+ *
+ * @param name
+ * Name or ID of the message. Cannot be null.
+ * @param value
+ * The actual message content. Cannot be null.
+ */
+ public Message(String name, String value) {
+ assert name != null;
+ assert value != null;
+
+ this.name = name;
+ this.value = value;
+ }
+
+ @OslcDescription("The name of the message")
+ @OslcPropertyDefinition(NAMESPACE_URI_JAZZ_QM + "name")
+ @OslcTitle("Name")
+ @OslcOccurs(Occurs.ExactlyOne)
+ @OslcValueType(ValueType.String)
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @OslcDescription("The actual message content")
+ @OslcPropertyDefinition(NAMESPACE_URI_JAZZ_QM + "value")
+ @OslcTitle("Value")
+ @OslcOccurs(Occurs.ExactlyOne)
+ @OslcValueType(ValueType.XMLLiteral)
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+}
diff --git a/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/RQMAutomationSample.java b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/RQMAutomationSample.java
index 2833048..96be6ef 100644
--- a/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/RQMAutomationSample.java
+++ b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/RQMAutomationSample.java
@@ -146,16 +146,18 @@ public class RQMAutomationSample implements IConstants, IAutomationRequestHandle
// An example of how to get the script for the AutomationRequest.
// The script might contain references to resources needed to
// execute the test.
+ adapter.sendMessageForRequest(new Message("LYO_1", "Downloading script document"), request);
+
Document script = adapter.getScriptDocument(request);
+ adapter.sendMessageForRequest(new Message("LYO_2", "Script document successfully downloaded"), request);
+
// update progress indication
- adapter.setProgress(request, 50);
+ adapter.sendProgressForRequest(50, request);
// execute the script with the parameters from the Automation Request
- executeScript(script, request.getInputParameters());
-
- // update progress indication
- adapter.setProgress(request, 99);
+ executeScript(script, request.getInputParameters(), adapter,
+ request);
// Upload an attachment for the result
File attachment = getSampleFile();
@@ -176,6 +178,9 @@ public class RQMAutomationSample implements IConstants, IAutomationRequestHandle
result.getExtendedProperties().put(PROPERTY_RQM_END_TIME,
new Date(System.currentTimeMillis()));
+ // update progress indication
+ adapter.sendProgressForRequest(99, request);
+
} catch (Exception e) {
// cancel the request since it could not be completed
@@ -197,9 +202,13 @@ public class RQMAutomationSample implements IConstants, IAutomationRequestHandle
* @param script
* @param inputParameters
* @throws InterruptedException
+ * @throws AutomationException
*/
private void executeScript(Document script,
- ParameterInstance[] inputParameters) throws InterruptedException {
+ ParameterInstance[] inputParameters, AutomationAdapter adapter,
+ AutomationRequest request) throws InterruptedException,
+ AutomationException {
+
String scriptTitle = script.getDocumentElement()
.getElementsByTagNameNS(NAMESPACE_URI_DC_ELEMENTS, "title")
@@ -219,6 +228,13 @@ public class RQMAutomationSample implements IConstants, IAutomationRequestHandle
*/
Thread.sleep(1000);
+ // Update the request status
+ StatusResponse statusResponse = new StatusResponse(
+ StatusResponse.STATUS_OK,
+ "Script '" + scriptTitle + "' was executed successfully.");
+
+ adapter.sendStatusForRequest(statusResponse, request);
+
}
/**
diff --git a/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/StatusResponse.java b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/StatusResponse.java
new file mode 100644
index 0000000..0011108
--- /dev/null
+++ b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/automation/StatusResponse.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Paul McMahan <pmcmahan@us.ibm.com> - initial implementation
+ *******************************************************************************/
+package org.eclipse.lyo.client.oslc.samples.automation;
+
+import java.util.logging.Logger;
+
+import org.eclipse.lyo.oslc4j.core.annotation.OslcDescription;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcNamespace;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcOccurs;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcPropertyDefinition;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcResourceShape;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcTitle;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcValueType;
+import org.eclipse.lyo.oslc4j.core.model.AbstractResource;
+import org.eclipse.lyo.oslc4j.core.model.Occurs;
+import org.eclipse.lyo.oslc4j.core.model.ValueType;
+
+@OslcResourceShape(title = "Status Response Resource Shape", describes = IConstants.TYPE_STATUS_RESPONSE)
+@OslcNamespace(IConstants.NAMESPACE_URI_JAZZ_QM)
+public class StatusResponse extends AbstractResource implements IConstants {
+
+ private static final Logger logger = Logger.getLogger(StatusResponse.class.getName());
+
+ /**
+ * Starting value for normal informational status message
+ */
+ public static final int STATUS_INFORMATIONAL = 100;
+
+ /**
+ * Starting value for success messages
+ */
+ public static final int STATUS_OK = 200;
+
+ /**
+ * Starting value for warning messages
+ */
+ public static final int STATUS_WARNING = 300;
+
+ /**
+ * Starting value for error messages
+ */
+ public static final int STATUS_ERROR = 400;
+
+ private int statusCode;
+
+ private String status;
+
+ /**
+ * Create a new StatusResponse object with the provided statusCode and
+ * status message. The expected range is 100-599.
+ *
+ * @param statusCode
+ * @param status
+ * @see @link {@link StatusResponse#STATUS_INFORMATIONAL}
+ * @see @link {@link StatusResponse#STATUS_OK}
+ * @see @link {@link StatusResponse#STATUS_WARNING}
+ * @see @link {@link StatusResponse#STATUS_ERROR}
+ */
+ public StatusResponse(int statusCode, String status) {
+ this.status = status;
+ setStatusCode(statusCode);
+ }
+
+ @OslcDescription("The severity of the status")
+ @OslcPropertyDefinition(NAMESPACE_URI_JAZZ_QM + "statusCode")
+ @OslcTitle("Status Code")
+ @OslcOccurs(Occurs.ExactlyOne)
+ @OslcValueType(ValueType.Integer)
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ /**
+ * Set the status code for this response. The expected range is 100-599.
+ *
+ * @param statusCode
+ * @see @link {@link StatusResponse#STATUS_INFORMATIONAL}
+ * @see @link {@link StatusResponse#STATUS_OK}
+ * @see @link {@link StatusResponse#STATUS_WARNING}
+ * @see @link {@link StatusResponse#STATUS_ERROR}
+ */
+ public void setStatusCode(int statusCode) {
+ this.statusCode = statusCode;
+
+ if (statusCode < 100 || statusCode > 599) {
+
+ logger.warning("status code not in expected range: " + statusCode);
+
+ }
+ }
+
+ @OslcDescription("Human friendly description of the status")
+ @OslcPropertyDefinition(NAMESPACE_URI_JAZZ_QM + "status")
+ @OslcTitle("Status")
+ @OslcOccurs(Occurs.ZeroOrOne)
+ @OslcValueType(ValueType.String)
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+}