Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* JBoss, Home of Professional Open Source
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.jboss.as.server.deployment;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CONTENT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEPLOYMENT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RUNTIME_NAME;
import static org.jboss.as.server.deployment.DeploymentHandlerUtils.getContents;
import org.jboss.as.server.services.security.AbstractVaultReader;
import static org.jboss.msc.service.ServiceController.Mode.REMOVE;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ServiceVerificationHandler;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.server.ServerLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.AbstractServiceListener;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.vfs.VirtualFile;
/**
* Utility methods used by operation handlers involved with deployment.
*
* This class is part of the runtime operation and should not have any reference to dmr.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
public class DeploymentHandlerUtil {
static class ContentItem {
// either hash or
private byte[] hash;
private String path;
private String relativeTo;
private boolean isArchive;
ContentItem(final byte[] hash) {
assert hash != null : "hash is null";
this.hash = hash;
}
ContentItem(final String path, final String relativeTo, final boolean isArchive) {
assert path != null : "path is null";
this.path = path;
this.relativeTo = relativeTo;
this.isArchive = isArchive;
}
byte[] getHash() {
return hash;
}
}
private DeploymentHandlerUtil() {
}
public static void deploy(final OperationContext context, final String deploymentUnitName, final String managementName, final AbstractVaultReader vaultReader, final ContentItem... contents) throws OperationFailedException {
assert contents != null : "contents is null";
if (context.isNormalServer()) {
//
final Resource deployment = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
final ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
final ManagementResourceRegistration mutableRegistration = context.getResourceRegistrationForUpdate();
DeploymentModelUtils.cleanup(deployment);
context.addStep(new OperationStepHandler() {
public void execute(OperationContext context, ModelNode operation) {
final ServiceName deploymentUnitServiceName = Services.deploymentUnitName(deploymentUnitName);
final ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
final ServiceController> deploymentController = serviceRegistry.getService(deploymentUnitServiceName);
if (deploymentController != null) {
final ServiceVerificationHandler verificationHandler = new ServiceVerificationHandler();
deploymentController.addListener(verificationHandler);
deploymentController.setMode(ServiceController.Mode.ACTIVE);
context.addStep(verificationHandler, OperationContext.Stage.VERIFY);
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
deploymentController.setMode(ServiceController.Mode.NEVER);
}
});
} else {
final ServiceVerificationHandler verificationHandler = new ServiceVerificationHandler();
final Collection> controllers = doDeploy(context, deploymentUnitName, managementName, verificationHandler, deployment, registration, mutableRegistration, vaultReader, contents);
context.addStep(verificationHandler, OperationContext.Stage.VERIFY);
context.completeStep(new OperationContext.ResultHandler() {
@Override
public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) {
if(resultAction == OperationContext.ResultAction.ROLLBACK) {
for(ServiceController> controller : controllers) {
context.removeService(controller.getName());
}
if (context.hasFailureDescription()) {
ServerLogger.ROOT_LOGGER.deploymentRolledBack(deploymentUnitName, getFormattedFailureDescription(context));
} else {
ServerLogger.ROOT_LOGGER.deploymentRolledBackWithNoMessage(deploymentUnitName);
}
} else {
ServerLogger.ROOT_LOGGER.deploymentDeployed(managementName, deploymentUnitName);
}
}
});
}
}
}, OperationContext.Stage.RUNTIME);
}
}
public static Collection> doDeploy(final OperationContext context, final String deploymentUnitName, final String managementName, final ServiceVerificationHandler verificationHandler,
final Resource deploymentResource, final ImmutableManagementResourceRegistration registration, final ManagementResourceRegistration mutableRegistration, final AbstractVaultReader vaultReader, final ContentItem... contents) {
final ServiceName deploymentUnitServiceName = Services.deploymentUnitName(deploymentUnitName);
final List> controllers = new ArrayList>();
final ServiceTarget serviceTarget = context.getServiceTarget();
final ServiceController> contentService;
// TODO: overlay service
final ServiceName contentsServiceName = deploymentUnitServiceName.append("contents");
if (contents[0].hash != null)
contentService = ContentServitor.addService(serviceTarget, contentsServiceName, contents[0].hash, verificationHandler);
else {
final String path = contents[0].path;
final String relativeTo = contents[0].relativeTo;
contentService = PathContentServitor.addService(serviceTarget, contentsServiceName, path, relativeTo, verificationHandler);
}
controllers.add(contentService);
final RootDeploymentUnitService service = new RootDeploymentUnitService(deploymentUnitName, managementName, null, registration, mutableRegistration, deploymentResource, verificationHandler, vaultReader);
final ServiceController deploymentUnitController = serviceTarget.addService(deploymentUnitServiceName, service)
.addDependency(Services.JBOSS_DEPLOYMENT_CHAINS, DeployerChains.class, service.getDeployerChainsInjector())
.addDependency(DeploymentMountProvider.SERVICE_NAME, DeploymentMountProvider.class, service.getServerDeploymentRepositoryInjector())
.addDependency(contentsServiceName, VirtualFile.class, service.contentsInjector)
.addListener(verificationHandler)
.setInitialMode(ServiceController.Mode.ACTIVE)
.install();
controllers.add(deploymentUnitController);
contentService.addListener(new AbstractServiceListener