Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add ability to add content as part of the deployment overlay content …

…add operation
  • Loading branch information...
commit 22fd8dcb1a8871769d8fb0d5ad2b848808f0e863 1 parent 9635f9a
@stuartwdouglas stuartwdouglas authored
View
7 controller/src/main/resources/org/jboss/as/controller/descriptions/common/LocalDescriptions.properties
@@ -385,5 +385,8 @@ deployment-overlay.deployment.regular-expression=If the deployment name is a reg
deployment-overlay.content.add=Adds a piece of content to a deployment overlay
deployment-overlay.content.remove=Removes a piece of content
deployment-overlay.content.path=The archive path that this content item overrides. e.g. To override a web.xml in a war packaged in an ear this would be mywar.war/WEB-INF/web.xml .
-deployment-overlay.content.content=The content hash
-
+deployment-overlay.content.content=The deployment overlay content item
+deployment-overlay.content.content.hash=The content hash
+deployment-overlay.content.content.input-stream-index=The index into the operation's attached input streams of the input stream that contains deployment content that should be uploaded to the domain's or standalone server's deployment content repository.
+deployment-overlay.content.content.bytes=Byte array containing the deployment content that should uploaded to the domain's or standalone server's deployment content repository..
+deployment-overlay.content.content.url=The URL at which the deployment content is available for upload to the domain's or standalone server's deployment content repository.. Note that the URL must be accessible from the target of the operation (i.e. the Domain Controller or standalone server).
View
6 server/src/main/java/org/jboss/as/server/ServerLogger.java
@@ -392,6 +392,12 @@
@LogMessage(level = WARN)
@Message(id = 15968, value= "jboss-deployment-dependencies cannot be used in a sub deployment, it must be specified at ear level: %s")
void deploymentDependenciesAreATopLevelElement(String name);
+
+ @LogMessage(level = Logger.Level.ERROR)
+ @Message(id = 15969, value = "No deployment overlay content with hash %s is available in the deployment content repository for deployment %s at location %s. Because this Host Controller is booting in ADMIN-ONLY mode, boot will be allowed to proceed to provide administrators an opportunity to correct this problem. If this Host Controller were not in ADMIN-ONLY mode this would be a fatal boot failure.")
+ void reportAdminOnlyMissingDeploymentOverlayContent(String contentHash, String deploymentName, String contentName);
+
+
// NOTE
}
View
9 server/src/main/java/org/jboss/as/server/ServerMessages.java
@@ -441,7 +441,7 @@ OperationFailedException illegalCombinationOfHttpManagementInterfaceConfiguratio
@Message(id = 18716, value = "Could not create server base directory: %s")
IllegalStateException couldNotCreateServerBaseDirectory(File file);
- @Message(id = 18717, value = "No deployment content with hash %s is available in the deployment content repository for deployment '%s'. This is a fatal boot error. To correct the problem, either restart with the --admin-only switch set and use the CLI to install the missing content or remove it from the configuration, or remove the deployment from the xml configuraiton file and restart.")
+ @Message(id = 18717, value = "No deployment content with hash %s is available in the deployment content repository for deployment '%s'. This is a fatal boot error. To correct the problem, either restart with the --admin-only switch set and use the CLI to install the missing content or remove it from the configuration, or remove the deployment from the xml configuration file and restart.")
OperationFailedException noSuchDeploymentContentAtBoot(String contentHash, String deploymentName);
/** Label for DEBUG log listing of the server's system properties */
@@ -636,4 +636,11 @@ OperationFailedException illegalCombinationOfHttpManagementInterfaceConfiguratio
@Message(id = 18777, value = "Wildcard character * is only allowed at the beginning or end of the deployment name %s")
OperationFailedException wildcardOnlyAllowedAtStartOrEnd(String str);
+
+
+ @Message(id = 18778, value = "No deployment overlay content with hash %s is available in the deployment content repository for deployment overlay '%s' at location %s. This is a fatal boot error. To correct the problem, either restart with the --admin-only switch set and use the CLI to install the missing content or remove it from the configuration, or remove the deployment overlay from the xml configuration file and restart.")
+ OperationFailedException noSuchDeploymentOverlayContentAtBoot(String contentHash, String deploymentOverlayName, String contentFile);
+
+ @Message(id = 18779, value = "No deployment overlay content with hash %s is available in the deployment content repository.")
+ OperationFailedException noSuchDeploymentOverlayContent(String hash);
}
View
154 server/src/main/java/org/jboss/as/server/deploymentoverlay/ContentAdd.java
@@ -1,26 +1,50 @@
package org.jboss.as.server.deploymentoverlay;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
import java.util.Arrays;
import java.util.List;
import org.jboss.as.controller.AbstractAddStepHandler;
import org.jboss.as.controller.AttributeDefinition;
+import org.jboss.as.controller.HashUtil;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
+import org.jboss.as.controller.RunningMode;
import org.jboss.as.controller.ServiceVerificationHandler;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
+import org.jboss.as.controller.operations.validation.AbstractParameterValidator;
+import org.jboss.as.controller.operations.validation.ListValidator;
+import org.jboss.as.controller.operations.validation.ModelTypeValidator;
+import org.jboss.as.controller.operations.validation.ParametersOfValidator;
+import org.jboss.as.controller.operations.validation.ParametersValidator;
+import org.jboss.as.controller.operations.validation.StringLengthValidator;
+import org.jboss.as.controller.registry.Resource;
+import org.jboss.as.protocol.StreamUtils;
import org.jboss.as.repository.ContentRepository;
import org.jboss.as.repository.DeploymentFileRepository;
+import org.jboss.as.server.ServerLogger;
import org.jboss.as.server.ServerMessages;
-import org.jboss.as.server.deploymentoverlay.service.DeploymentOverlayService;
import org.jboss.as.server.deploymentoverlay.service.ContentService;
+import org.jboss.as.server.deploymentoverlay.service.DeploymentOverlayService;
import org.jboss.dmr.ModelNode;
+import org.jboss.dmr.ModelType;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.BYTES;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CONTENT;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ENABLED;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HASH;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.INPUT_STREAM_INDEX;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RUNTIME_NAME;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.URL;
+import static org.jboss.as.controller.operations.validation.ChainedParameterValidator.chain;
/**
* @author Stuart Douglas
@@ -30,21 +54,58 @@
protected final ContentRepository contentRepository;
private final DeploymentFileRepository remoteRepository;
+ protected final ParametersValidator validator = new ParametersValidator();
+ protected final ParametersValidator managedContentValidator = new ParametersValidator();
+
public ContentAdd(final ContentRepository contentRepository, final DeploymentFileRepository remoteRepository) {
this.contentRepository = contentRepository;
this.remoteRepository = remoteRepository;
+ this.validator.registerValidator(RUNTIME_NAME, new StringLengthValidator(1, Integer.MAX_VALUE, true, false));
+ this.validator.registerValidator(ENABLED, new ModelTypeValidator(ModelType.BOOLEAN, true));
+ final ParametersValidator contentValidator = new ParametersValidator();
+ // existing managed content
+ contentValidator.registerValidator(HASH, new ModelTypeValidator(ModelType.BYTES, true));
+ // content additions
+ contentValidator.registerValidator(INPUT_STREAM_INDEX, new ModelTypeValidator(ModelType.INT, true));
+ contentValidator.registerValidator(BYTES, new ModelTypeValidator(ModelType.BYTES, true));
+ contentValidator.registerValidator(URL, new StringLengthValidator(1, true));
+ this.validator.registerValidator(CONTENT, chain(new ListValidator(new ParametersOfValidator(contentValidator)),
+ new AbstractParameterValidator() {
+ @Override
+ public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException {
+ validateOnePieceOfContent(value);
+ }
+ }));
+ this.managedContentValidator.registerValidator(HASH, new ModelTypeValidator(ModelType.BYTES));
+ }
+
+ @Override
+ protected void populateModel(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException {
+ final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
+ final String path = address.getLastElement().getValue();
+ final String name = address.getElement(address.size() - 2).getValue();
+ ModelNode content = operation.get(CONTENT);
+ if (content.hasDefined(HASH)) {
+ managedContentValidator.validate(content);
+ byte[] hash = content.require(HASH).asBytes();
+ addFromHash(hash, name, path, context);
+ } else {
+ addFromContentAdditionParameter(context, content);
+ }
+ super.populateModel(context, operation, resource);
}
@Override
protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException {
- for(AttributeDefinition attr : ContentDefinition.attributes()) {
+
+ for (AttributeDefinition attr : ContentDefinition.attributes()) {
attr.validateAndSet(operation, model);
}
- final byte[] hash = operation.get(ContentDefinition.CONTENT.getName()).asBytes();
- if(remoteRepository != null) {
+ final byte[] hash = operation.get(CONTENT).get(HASH).asBytes();
+ if (remoteRepository != null) {
remoteRepository.getDeploymentFiles(hash);
}
- if(!contentRepository.syncContent(hash)) {
+ if (!contentRepository.syncContent(hash)) {
throw ServerMessages.MESSAGES.noSuchDeploymentContent(Arrays.toString(hash));
}
}
@@ -55,7 +116,7 @@ protected void performRuntime(final OperationContext context, final ModelNode op
final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
final String path = address.getLastElement().getValue();
final String name = address.getElement(address.size() - 2).getValue();
- final byte[] content = model.get(ModelDescriptionConstants.CONTENT).asBytes();
+ final byte[] content = model.get(ModelDescriptionConstants.CONTENT).get(HASH).asBytes();
installServices(context, verificationHandler, newControllers, name, path, content);
@@ -68,12 +129,89 @@ static void installServices(final OperationContext context, final ServiceVerific
ServiceBuilder<ContentService> builder = context.getServiceTarget().addService(serviceName, service)
.addDependency(DeploymentOverlayService.SERVICE_NAME.append(name), DeploymentOverlayService.class, service.getDeploymentOverlayServiceInjectedValue())
.addDependency(ContentRepository.SERVICE_NAME, ContentRepository.class, service.getContentRepositoryInjectedValue());
- if(verificationHandler != null) {
+ if (verificationHandler != null) {
builder.addListener(verificationHandler);
}
final ServiceController<ContentService> controller = builder.install();
- if(newControllers != null) {
+ if (newControllers != null) {
newControllers.add(controller);
}
}
+
+ protected static void validateOnePieceOfContent(final ModelNode content) throws OperationFailedException {
+ if (content.asList().size() != 1)
+ throw ServerMessages.MESSAGES.multipleContentItemsNotSupported();
+ }
+
+ byte[] addFromHash(byte[] hash, String deploymentOverlayName, final String contentName, final OperationContext context) throws OperationFailedException {
+ if (!contentRepository.syncContent(hash)) {
+ if (context.isBooting()) {
+ if (context.getRunningMode() == RunningMode.ADMIN_ONLY) {
+ // The deployment content is missing, which would be a fatal boot error if we were going to actually
+ // install services. In ADMIN-ONLY mode we allow it to give the admin a chance to correct the problem
+ ServerLogger.DEPLOYMENT_LOGGER.reportAdminOnlyMissingDeploymentOverlayContent(HashUtil.bytesToHexString(hash), deploymentOverlayName, contentName);
+
+ } else {
+ throw ServerMessages.MESSAGES.noSuchDeploymentOverlayContentAtBoot(HashUtil.bytesToHexString(hash), deploymentOverlayName, contentName);
+ }
+ } else {
+ throw ServerMessages.MESSAGES.noSuchDeploymentOverlayContent(HashUtil.bytesToHexString(hash));
+ }
+ }
+ return hash;
+ }
+
+ byte[] addFromContentAdditionParameter(OperationContext context, ModelNode contentItemNode) throws OperationFailedException {
+ byte[] hash;
+ InputStream in = getInputStream(context, contentItemNode);
+ try {
+ try {
+ hash = contentRepository.addContent(in);
+ } catch (IOException e) {
+ throw createFailureException(e.toString());
+ }
+
+ } finally {
+ StreamUtils.safeClose(in);
+ }
+ contentItemNode.clear(); // AS7-1029
+ contentItemNode.get(HASH).set(hash);
+ return hash;
+ }
+
+ protected static OperationFailedException createFailureException(String msg) {
+ return new OperationFailedException(new ModelNode(msg));
+ }
+
+ protected static InputStream getInputStream(OperationContext context, ModelNode operation) throws OperationFailedException {
+ InputStream in = null;
+ if (operation.hasDefined(INPUT_STREAM_INDEX)) {
+ int streamIndex = operation.get(INPUT_STREAM_INDEX).asInt();
+ int maxIndex = context.getAttachmentStreamCount();
+ if (streamIndex > maxIndex) {
+ throw ServerMessages.MESSAGES.invalidStreamIndex(INPUT_STREAM_INDEX, streamIndex, maxIndex);
+ }
+ in = context.getAttachmentStream(streamIndex);
+ } else if (operation.hasDefined(BYTES)) {
+ try {
+ in = new ByteArrayInputStream(operation.get(BYTES).asBytes());
+ } catch (IllegalArgumentException iae) {
+ throw ServerMessages.MESSAGES.invalidStreamBytes(BYTES);
+ }
+ } else if (operation.hasDefined(URL)) {
+ final String urlSpec = operation.get(URL).asString();
+ try {
+ in = new java.net.URL(urlSpec).openStream();
+ } catch (MalformedURLException e) {
+ throw ServerMessages.MESSAGES.invalidStreamURL(e, urlSpec);
+ } catch (IOException e) {
+ throw ServerMessages.MESSAGES.invalidStreamURL(e, urlSpec);
+ }
+ }
+ if (in == null) {
+ // Won't happen, as we call hasValidContentAdditionParameterDefined first
+ throw new IllegalStateException();
+ }
+ return in;
+ }
}
View
95 server/src/main/java/org/jboss/as/server/deploymentoverlay/ContentDefinition.java
@@ -1,26 +1,52 @@
package org.jboss.as.server.deploymentoverlay;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
import org.jboss.as.controller.AttributeDefinition;
+import org.jboss.as.controller.AttributeMarshaller;
+import org.jboss.as.controller.ParameterCorrector;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleResourceDefinition;
+import org.jboss.as.controller.client.helpers.MeasurementUnit;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
+import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.descriptions.common.CommonDescriptions;
+import org.jboss.as.controller.operations.validation.ParameterValidator;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.repository.ContentRepository;
import org.jboss.as.repository.DeploymentFileRepository;
+import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ARCHIVE;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ATTRIBUTES;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.BYTES;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CONTENT;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXPRESSIONS_ALLOWED;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HASH;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.INPUT_STREAM_INDEX;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MAX_LENGTH;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MIN;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MIN_LENGTH;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NILLABLE;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PATH;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RELATIVE_TO;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REQUIRED;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.TYPE;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.URL;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE_TYPE;
+
/**
* @author Stuart Douglas
*/
public class ContentDefinition extends SimpleResourceDefinition {
- static final SimpleAttributeDefinition CONTENT =
- new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.CONTENT, ModelType.BYTES, false)
- .setFlags(AttributeAccess.Flag.RESTART_NONE)
- .build();
+ static final ContentAttributeDefinition CONTENT =
+ new ContentAttributeDefinition(ModelDescriptionConstants.CONTENT, ModelType.OBJECT, false);
private static final AttributeDefinition[] ATTRIBUTES = {CONTENT};
@@ -41,4 +67,65 @@ public void registerAttributes(final ManagementResourceRegistration resourceRegi
resourceRegistration.registerReadOnlyAttribute(attr, null);
}
}
+
+ public static final class ContentAttributeDefinition extends SimpleAttributeDefinition {
+
+
+ private ContentAttributeDefinition(final String name, final ModelType type, final boolean allowNull) {
+ super(name, type, allowNull);
+ }
+
+ @Override
+ public ModelNode addOperationParameterDescription(ModelNode resourceDescription, String operationName,
+ ResourceDescriptionResolver resolver, Locale locale, ResourceBundle bundle) {
+ final ModelNode result = super.addOperationParameterDescription(resourceDescription, operationName, resolver, locale, bundle);
+ addOperationParameterValueTypeDescription(result, operationName, resolver, locale, bundle);
+ return result;
+ }
+
+
+ private void addOperationParameterValueTypeDescription(ModelNode result, String operationName, ResourceDescriptionResolver resolver, Locale locale, ResourceBundle bundle) {
+ final ModelNode valueType = getNoTextValueTypeDescription(result);
+ valueType.get(INPUT_STREAM_INDEX, DESCRIPTION).set(resolver.getOperationParameterValueTypeDescription(operationName, getName(), locale, bundle, INPUT_STREAM_INDEX));
+ valueType.get(HASH, DESCRIPTION).set(resolver.getOperationParameterValueTypeDescription(operationName, getName(), locale, bundle, HASH));
+ valueType.get(BYTES, DESCRIPTION).set(resolver.getOperationParameterValueTypeDescription(operationName, getName(), locale, bundle, BYTES));
+ valueType.get(URL, DESCRIPTION).set(resolver.getOperationParameterValueTypeDescription(operationName, getName(), locale, bundle, URL));
+ }
+
+ private ModelNode getNoTextValueTypeDescription(final ModelNode parent) {
+ final ModelNode valueType = parent.get(VALUE_TYPE);
+ final ModelNode inputStreamIndex = valueType.get(INPUT_STREAM_INDEX);
+ inputStreamIndex.get(TYPE).set(ModelType.INT);
+ inputStreamIndex.get(INPUT_STREAM_INDEX, DESCRIPTION);
+ inputStreamIndex.get(INPUT_STREAM_INDEX, REQUIRED).set(false);
+ inputStreamIndex.get(INPUT_STREAM_INDEX, MIN).set(0);
+ inputStreamIndex.get(INPUT_STREAM_INDEX, NILLABLE).set(true);
+
+ final ModelNode hash = valueType.get(HASH);
+ hash.get(TYPE).set(ModelType.BYTES);
+ hash.get(HASH, DESCRIPTION);
+ hash.get(HASH, REQUIRED).set(false);
+ hash.get(HASH, MIN_LENGTH).set(20);
+ hash.get(HASH, MAX_LENGTH).set(20);
+ hash.get(HASH, NILLABLE).set(true);
+
+ final ModelNode bytes = valueType.get(BYTES);
+ bytes.get(TYPE).set(ModelType.BYTES);
+ bytes.get(BYTES, DESCRIPTION);
+ bytes.get(BYTES, REQUIRED).set(false);
+ bytes.get(BYTES, MIN_LENGTH).set(1);
+ bytes.get(BYTES, NILLABLE).set(true);
+
+ final ModelNode url = valueType.get(URL);
+ url.get(TYPE).set(ModelType.STRING);
+ url.get(DESCRIPTION);
+ url.get(REQUIRED).set(false);
+ url.get(MIN_LENGTH).set(1);
+ url.get(NILLABLE).set(true);
+
+ return valueType;
+ }
+
+
+ }
}
View
4 server/src/main/java/org/jboss/as/server/parsing/CommonXml.java
@@ -1156,7 +1156,7 @@ protected void parseContentOverride(final String name, final XMLExtendedStreamRe
final ModelNode op = new ModelNode();
op.get(OP).set(ADD);
op.get(OP_ADDR).set(address);
- op.get(CONTENT).set(content);
+ op.get(CONTENT).get(HASH).set(content);
list.add(op);
}
@@ -1593,7 +1593,7 @@ protected void writeDeploymentOverlays(final XMLExtendedStreamWriter writer, fin
final Set<String> overrides = overridesNode.keys();
for (final String override : overrides) {
final ModelNode overrideNode = overridesNode.get(override);
- final String content = HashUtil.bytesToHexString(overrideNode.require(CONTENT).asBytes());
+ final String content = HashUtil.bytesToHexString(overrideNode.require(CONTENT).require(HASH).asBytes());
writer.writeStartElement(Element.CONTENT.getLocalName());
writeAttribute(writer, Attribute.PATH, override);
writeAttribute(writer, Attribute.CONTENT, content);
View
26 .../src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/DeploymentOverlayTestCase.java
@@ -11,6 +11,7 @@
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
+import org.jboss.as.controller.client.OperationBuilder;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.test.integration.management.ManagementOperations;
import org.jboss.as.test.integration.management.util.MgmtOperationException;
@@ -18,6 +19,7 @@
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
@@ -58,7 +60,7 @@ public void setup(final ManagementClient managementClient, final String containe
addr.add(ModelDescriptionConstants.CONTENT, "WEB-INF/web.xml");
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
- op.get(ModelDescriptionConstants.CONTENT).set(result);
+ op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.HASH).set(result);
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
//add the non-wildcard link
@@ -77,34 +79,26 @@ public void setup(final ManagementClient managementClient, final String containe
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
op = new ModelNode();
- op.get(ModelDescriptionConstants.OP_ADDR).set(new ModelNode());
- op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.UPLOAD_DEPLOYMENT_BYTES);
- op.get(ModelDescriptionConstants.BYTES).set(FileUtils.readFile(DeploymentOverlayTestCase.class, "wildcard-override.xml").getBytes());
- result = ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
-
- op = new ModelNode();
addr = new ModelNode();
addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD);
addr.add(ModelDescriptionConstants.CONTENT, "WEB-INF/web.xml");
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
- op.get(ModelDescriptionConstants.CONTENT).set(result);
+ op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.BYTES).set(FileUtils.readFile(DeploymentOverlayTestCase.class, "wildcard-override.xml").getBytes());
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
op = new ModelNode();
- op.get(ModelDescriptionConstants.OP_ADDR).set(new ModelNode());
- op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.UPLOAD_DEPLOYMENT_BYTES);
- op.get(ModelDescriptionConstants.BYTES).set(FileUtils.readFile(DeploymentOverlayTestCase.class, "wildcard-new-file").getBytes());
- result = ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
-
- op = new ModelNode();
addr = new ModelNode();
addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD);
addr.add(ModelDescriptionConstants.CONTENT, "WEB-INF/classes/wildcard-new-file");
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
- op.get(ModelDescriptionConstants.CONTENT).set(result);
- ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
+ op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0);
+
+
+ OperationBuilder builder = new OperationBuilder(op, true);
+ builder.addInputStream(DeploymentOverlayTestCase.class.getResourceAsStream("wildcard-new-file"));
+ ManagementOperations.executeOperation(managementClient.getControllerClient(), builder.build());
//add the wildcard link
op = new ModelNode();
View
19 testsuite/shared/src/main/java/org/jboss/as/test/integration/management/ManagementOperations.java
@@ -4,6 +4,7 @@
import java.util.List;
import org.jboss.as.controller.client.ModelControllerClient;
+import org.jboss.as.controller.client.Operation;
import org.jboss.as.test.integration.management.util.MgmtOperationException;
import org.jboss.dmr.ModelNode;
@@ -37,6 +38,14 @@ public static ModelNode executeOperation(final ModelControllerClient client, fin
}
/**
+ * Executes a management operation and returns the 'result' ModelNode of the server output. If the operation fails an exception will be thrown
+ */
+ public static ModelNode executeOperation(final ModelControllerClient client, final Operation op) throws IOException, MgmtOperationException {
+ return executeOperation(client, op, true);
+ }
+
+
+ /**
* Executes a management operation and returns the raw ModelNode that is returned from the server.
*
* It is up to the client to check it the result is a success or not
@@ -60,4 +69,14 @@ private static ModelNode executeOperation(final ModelControllerClient client, fi
return ret.get(RESULT);
}
+
+ private static ModelNode executeOperation(final ModelControllerClient client, final Operation op, boolean unwrapResult) throws IOException, MgmtOperationException {
+ ModelNode ret = client.execute(op);
+ if (!unwrapResult) return ret;
+
+ if (!SUCCESS.equals(ret.get(OUTCOME).asString())) {
+ throw new MgmtOperationException("Management operation failed: " + ret.get(FAILURE_DESCRIPTION), op.getOperation(), ret);
+ }
+ return ret.get(RESULT);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.