Skip to content

Commit

Permalink
MODE-1859 - Fixed the removal of ModeShape services when a repository…
Browse files Browse the repository at this point in the history
… is removed. Refactored the general remove & recover operations, as they are very similar.
  • Loading branch information
Horia Chiorean committed Mar 20, 2013
1 parent aee0a09 commit 88809fa
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 213 deletions.
@@ -0,0 +1,92 @@
/*
* ModeShape (http://www.modeshape.org)
* See the COPYRIGHT.txt file distributed with this work for information
* regarding copyright ownership. Some portions may be licensed
* to Red Hat, Inc. under one or more contributor license agreements.
* See the AUTHORS.txt file in the distribution for a full listing of
* individual contributors.
*
* ModeShape is free software. Unless otherwise indicated, all code in ModeShape
* is licensed to you under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* ModeShape is distributed in the hope that it will be useful,
* but WITHOUT ANY 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 along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.modeshape.jboss.subsystem;

import java.util.List;
import org.jboss.as.controller.AbstractRemoveStepHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;

/**
* Base {@link AbstractRemoveStepHandler} which should be extended by all ModeShape subsystem services, as removal & recovery
* is similar for all.
*
* @author Horia Chiorean (hchiorea@redhat.com)
*/
abstract class AbstractModeShapeRemoveStepHandler extends AbstractRemoveStepHandler {

protected final Logger log = Logger.getLogger(getClass().getName());

@Override
protected void performRuntime( OperationContext context,
ModelNode operation,
ModelNode model ) throws OperationFailedException {
String repositoryName = null;

for (ServiceName serviceName : servicesToRemove(operation, model)) {
context.removeService(serviceName);
if (log.isDebugEnabled()) {
if (repositoryName == null) {
repositoryName = repositoryName(operation);
}
log.debugf("service '%s' removed for repository '%s'", serviceName, repositoryName);
}
}
}

@Override
protected void recoverServices( OperationContext context,
ModelNode operation,
ModelNode model ) throws OperationFailedException {
String repositoryName = null;

ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
for (ServiceName serviceName : servicesToRemove(operation, model)) {
context.getServiceTarget().addService(serviceName, serviceRegistry.getService(serviceName).getService());
if (log.isDebugEnabled()) {
if (repositoryName == null) {
repositoryName = repositoryName(operation);
}
log.debugf("service '%s' recovered for repository '%s'", serviceName, repositoryName);
}
}
}

abstract List<ServiceName> servicesToRemove( ModelNode operation,
ModelNode model );

String repositoryName(ModelNode operation) {
// Get the service addresses ...
final PathAddress serviceAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
// Get the repository name ...
return serviceAddress.getLastElement().getValue();
}
}
Expand Up @@ -65,11 +65,10 @@

public class AddRepository extends AbstractAddStepHandler {

private static final org.jboss.logging.Logger LOG = org.jboss.logging.Logger.getLogger(AddRepository.class.getPackage()
.getName());

public static final AddRepository INSTANCE = new AddRepository();

private static final org.jboss.logging.Logger LOG = org.jboss.logging.Logger.getLogger(AddRepository.class.getPackage()
.getName());
private AddRepository() {
}

Expand Down Expand Up @@ -223,8 +222,9 @@ protected void performRuntime( final OperationContext context,

// Set up the JNDI binder service ...
final ReferenceFactoryService<JcrRepository> referenceFactoryService = new ReferenceFactoryService<JcrRepository>();
final ServiceName referenceFactoryServiceName = repositoryServiceName.append("reference-factory");
final ServiceBuilder<?> referenceBuilder = target.addService(referenceFactoryServiceName, referenceFactoryService);
ServiceName referenceFactoryServiceName = ModeShapeServiceNames.referenceFactoryServiceName(repositoryName);
final ServiceBuilder<?> referenceBuilder = target.addService(referenceFactoryServiceName,
referenceFactoryService);
referenceBuilder.addDependency(repositoryServiceName, JcrRepository.class, referenceFactoryService.getInjector());
referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE);

Expand Down
Expand Up @@ -60,27 +60,30 @@ public static ServiceName dataDirectoryServiceName( String name ) {
/**
* Obtain the name of the service for the {@link IndexStorage} for the given repository name
*
* @param name the repository name
* @param repositoryName the repository name
* @return the service name
*/
public static ServiceName indexStorageServiceName( String name ) {
return ServiceName.of(ServiceName.JBOSS, "modeshape", name, "indexes");
public static ServiceName indexStorageServiceName( String repositoryName ) {
return ServiceName.of(ServiceName.JBOSS, "modeshape", repositoryName, "indexes");
}

public static ServiceName indexStorageDirectoryServiceName( String name ) {
return ServiceName.of(ServiceName.JBOSS, "modeshape", name, "indexes.dir");
public static ServiceName indexStorageDirectoryServiceName( String repositoryName ) {
return ServiceName.of(ServiceName.JBOSS, "modeshape", repositoryName, "indexes.dir");
}

public static ServiceName indexSourceStorageDirectoryServiceName( String name ) {
return ServiceName.of(ServiceName.JBOSS, "modeshape", name, "indexes.source-dir");
public static ServiceName indexSourceStorageDirectoryServiceName( String repositoryName ) {
return ServiceName.of(ServiceName.JBOSS, "modeshape", repositoryName, "indexes.source-dir");
}

public static ServiceName binaryStorageServiceName( String name ) {
return ServiceName.of(ServiceName.JBOSS, "modeshape", name, "binaries");
public static ServiceName binaryStorageServiceName( String repositoryName ) {
return ServiceName.of(ServiceName.JBOSS, "modeshape", repositoryName, "binaries");
}

public static ServiceName binaryStorageDirectoryServiceName( String name ) {
return ServiceName.of(ServiceName.JBOSS, "modeshape", name, "binaries.dir");
public static ServiceName binaryStorageDirectoryServiceName( String repositoryName ) {
return ServiceName.of(ServiceName.JBOSS, "modeshape", repositoryName, "binaries.dir");
}

public static ServiceName referenceFactoryServiceName( String repositoryName ) {
return repositoryServiceName(repositoryName).append("reference-factory");
}
}
Expand Up @@ -23,43 +23,29 @@
*/
package org.modeshape.jboss.subsystem;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import org.jboss.as.controller.AbstractRemoveStepHandler;
import org.jboss.as.controller.OperationContext;
import java.util.Arrays;
import java.util.List;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import org.jboss.msc.service.ServiceName;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;

class RemoveAuthenticator extends AbstractRemoveStepHandler {

private static final Logger log = Logger.getLogger(RemoveAuthenticator.class.getPackage().getName());
class RemoveAuthenticator extends AbstractModeShapeRemoveStepHandler {

public static final RemoveAuthenticator INSTANCE = new RemoveAuthenticator();
static final RemoveAuthenticator INSTANCE = new RemoveAuthenticator();

private RemoveAuthenticator() {
}

@Override
protected void performRuntime( OperationContext context,
ModelNode operation,
ModelNode model ) {
List<ServiceName> servicesToRemove( ModelNode operation,
ModelNode model ) {
// Get the service addresses ...
final PathAddress serviceAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
// Get the repository name ...
final String authenticatorName = serviceAddress.getLastElement().getValue();
final String repositoryName = serviceAddress.getElement(1).getValue();
// Remove the service ...
final ServiceName serviceName = ModeShapeServiceNames.authenticatorServiceName(repositoryName, authenticatorName);
context.removeService(serviceName);

log.debugf("authenticator '%s' removed for repository '%s'", authenticatorName, repositoryName);
}

@Override
protected void recoverServices( OperationContext context,
ModelNode operation,
ModelNode model ) {
// TODO: RE-ADD SERVICES
return Arrays.asList(ModeShapeServiceNames.authenticatorServiceName(repositoryName, authenticatorName));
}
}
Expand Up @@ -23,52 +23,33 @@
*/
package org.modeshape.jboss.subsystem;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import org.jboss.as.controller.AbstractRemoveStepHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.PathAddress;
import java.util.ArrayList;
import java.util.List;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import org.jboss.msc.service.ServiceName;

class RemoveBinaryStorage extends AbstractRemoveStepHandler {
class RemoveBinaryStorage extends AbstractModeShapeRemoveStepHandler {

protected static final Logger log = Logger.getLogger(RemoveBinaryStorage.class.getPackage().getName());

public static final RemoveBinaryStorage INSTANCE = new RemoveBinaryStorage();
static final RemoveBinaryStorage INSTANCE = new RemoveBinaryStorage();

private RemoveBinaryStorage() {
}

@Override
protected void performRuntime( OperationContext context,
ModelNode operation,
ModelNode model ) {
// Get the service addresses ...
final PathAddress serviceAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
// Get the repository name ...
final String repositoryName = serviceAddress.getElement(1).getValue();
final ServiceName serviceName = ModeShapeServiceNames.binaryStorageServiceName(repositoryName);

// Simply remove all services started by any/all of the Add*BinaryStorage operations ...
context.removeService(serviceName);
List<ServiceName> servicesToRemove( ModelNode operation,
ModelNode model ) {
String repositoryName = repositoryName(operation);
List<ServiceName> servicesToRemove = new ArrayList<ServiceName>();
servicesToRemove.add(ModeShapeServiceNames.binaryStorageServiceName(repositoryName));

// Now see if we need to remove the path service ...
//see if we need to remove the path service ...
if (model.has(ModelKeys.RELATIVE_TO)
&& model.get(ModelKeys.RELATIVE_TO).asString().contains(AddFileBinaryStorage.DATA_DIR_VARIABLE)) {
&& model.get(ModelKeys.RELATIVE_TO).asString().contains(AddFileBinaryStorage.DATA_DIR_VARIABLE)) {
// The binaries were stored in the data directory, so we need to remove the path service ...
ServiceName dirServiceName = ModeShapeServiceNames.binaryStorageDirectoryServiceName(repositoryName);
context.removeService(dirServiceName);
servicesToRemove.add(dirServiceName);
}

String service = serviceAddress.getLastElement().getValue();
log.debugf("binary storage '%s' removed for repository '%s'", service, repositoryName);
}

@Override
protected void recoverServices( OperationContext context,
ModelNode operation,
ModelNode model ) {
// TODO: RE-ADD SERVICES
return servicesToRemove;
}
}
Expand Up @@ -23,58 +23,35 @@
*/
package org.modeshape.jboss.subsystem;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import org.jboss.as.controller.AbstractRemoveStepHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.PathAddress;
import java.util.ArrayList;
import java.util.List;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import org.jboss.msc.service.ServiceName;

class RemoveIndexStorage extends AbstractRemoveStepHandler {
class RemoveIndexStorage extends AbstractModeShapeRemoveStepHandler {

protected static final Logger log = Logger.getLogger(RemoveIndexStorage.class.getPackage().getName());

public static final RemoveIndexStorage INSTANCE = new RemoveIndexStorage();
static final RemoveIndexStorage INSTANCE = new RemoveIndexStorage();

private RemoveIndexStorage() {
}

@Override
protected void performRuntime( OperationContext context,
ModelNode operation,
ModelNode model ) {
// Get the service addresses ...
final PathAddress serviceAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
// Get the repository name ...
final String repositoryName = serviceAddress.getElement(1).getValue();
final ServiceName serviceName = ModeShapeServiceNames.indexStorageServiceName(repositoryName);

// Simply remove all services started by any/all of the Add*IndexStorage operations ...
context.removeService(serviceName);
List<ServiceName> servicesToRemove( ModelNode operation,
ModelNode model ) {
String repositoryName = repositoryName(operation);
List<ServiceName> servicesToRemove = new ArrayList<ServiceName>();
servicesToRemove.add(ModeShapeServiceNames.indexStorageServiceName(repositoryName));

// Now see if we need to remove the path service ...
if (model.has(ModelKeys.RELATIVE_TO)
&& model.get(ModelKeys.RELATIVE_TO).asString().contains(AddLocalFileSystemIndexStorage.DATA_DIR_VARIABLE)) {
// The binaries were stored in the data directory, so we need to remove the path service ...
ServiceName dirServiceName = ModeShapeServiceNames.indexStorageDirectoryServiceName(repositoryName);
context.removeService(dirServiceName);
&& model.get(ModelKeys.RELATIVE_TO).asString().contains(AddLocalFileSystemIndexStorage.DATA_DIR_VARIABLE)) {
servicesToRemove.add(ModeShapeServiceNames.indexStorageDirectoryServiceName(repositoryName));
}
if (model.has(ModelKeys.SOURCE_RELATIVE_TO)
&& model.get(ModelKeys.SOURCE_RELATIVE_TO).asString().contains(AddLocalFileSystemIndexStorage.DATA_DIR_VARIABLE)) {
// The binaries were stored in the data directory, so we need to remove the path service ...
ServiceName dirServiceName = ModeShapeServiceNames.indexStorageDirectoryServiceName(repositoryName);
context.removeService(dirServiceName);
&& model.get(ModelKeys.SOURCE_RELATIVE_TO).asString().contains(AddLocalFileSystemIndexStorage.DATA_DIR_VARIABLE)) {
servicesToRemove.add(ModeShapeServiceNames.indexSourceStorageDirectoryServiceName(repositoryName));
}

String service = serviceAddress.getLastElement().getValue();
log.debugf("index storage '%s' removed for repository '%s'", service, repositoryName);
}

@Override
protected void recoverServices( OperationContext context,
ModelNode operation,
ModelNode model ) {
// TODO: RE-ADD SERVICES
return servicesToRemove;
}
}

0 comments on commit 88809fa

Please sign in to comment.