Skip to content

Commit

Permalink
Merge branch 'master' of github.com:teiid/teiid
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Nov 14, 2016
2 parents b285606 + 25578a7 commit f299ac3
Show file tree
Hide file tree
Showing 17 changed files with 330 additions and 195 deletions.
Expand Up @@ -104,6 +104,7 @@ public static enum Event implements BundleUtil.Event {
TEIID50105,
TEIID50106,
TEIID50107,
TEIID50108
TEIID50108,
TEIID50109
}
}
142 changes: 142 additions & 0 deletions jboss-integration/src/main/java/org/teiid/jboss/ResteasyEnabler.java
@@ -0,0 +1,142 @@
/*
* JBoss, Home of Professional Open Source.
* 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.
*
* This library is free software; you can redistribute it and/or
* modify it 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.
*
* This library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*/
package org.teiid.jboss;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;

import org.jboss.as.controller.ModelController;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
import org.teiid.adminapi.Admin;
import org.teiid.adminapi.AdminException;
import org.teiid.adminapi.VDB.Status;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.adminapi.jboss.AdminFactory;
import org.teiid.deployers.CompositeVDB;
import org.teiid.deployers.RestWarGenerator;
import org.teiid.deployers.VDBLifeCycleListener;
import org.teiid.deployers.VDBRepository;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.vdb.runtime.VDBKey;

public class ResteasyEnabler implements VDBLifeCycleListener, Service<Void> {
protected final InjectedValue<ModelController> controllerValue = new InjectedValue<ModelController>();
protected final InjectedValue<Executor> executorInjector = new InjectedValue<Executor>();
final InjectedValue<VDBRepository> vdbRepoInjector = new InjectedValue<VDBRepository>();

private HashMap<VDBKey, AtomicBoolean> deployed = new HashMap<VDBKey, AtomicBoolean>();
private RestWarGenerator generator;
private boolean started = false;

public ResteasyEnabler(RestWarGenerator generator) {
this.generator = generator;
}

@Override
public synchronized void added(String name, CompositeVDB vdb) {
this.deployed.put(vdb.getVDBKey(), new AtomicBoolean(false));
}

@Override
public void beforeRemove(String name, CompositeVDB cvdb) {
if (cvdb != null) {
this.deployed.remove(cvdb.getVDBKey());
}
}

@Override
public synchronized void finishedDeployment(String name, CompositeVDB cvdb) {
final VDBMetaData vdb = cvdb.getVDB();

if (!vdb.getStatus().equals(Status.ACTIVE) || !started) {
return;
}

final String warName = buildName(name, cvdb.getVDB().getVersion());
if (generator.hasRestMetadata(vdb) && this.deployed.get(cvdb.getVDBKey()).compareAndSet(false, true)) {
final Runnable job = new Runnable() {
@Override
public void run() {
try {
byte[] warContents = generator.getContent(vdb);
if (!vdb.getStatus().equals(Status.ACTIVE)) {
return;
}
if (warContents != null) {
//make it a non-persistent deployment
getAdmin().deploy(warName, new ByteArrayInputStream(warContents), false);
}
} catch (IOException e) {
LogManager.logWarning(LogConstants.CTX_RUNTIME, e,
IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50109, warName));
} catch (AdminException e) {
LogManager.logWarning(LogConstants.CTX_RUNTIME, e,
IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50109, warName));
}
}
};
getExecutor().execute(job);
}
}

@Override
public synchronized void removed(String name, CompositeVDB cvdb) {

}

private String buildName(String name, String version) {
return name+"_"+version +".war"; //$NON-NLS-1$ //$NON-NLS-2$
}

@Override
public Void getValue() throws IllegalStateException, IllegalArgumentException {
return null;
}

@Override
public void start(StartContext arg0) throws StartException {
started = true;
this.vdbRepoInjector.getValue().addListener(this);
}

@Override
public void stop(StopContext arg0) {
started = false;
}

Admin getAdmin() {
return AdminFactory.getInstance()
.createAdmin(controllerValue.getValue().createClient(executorInjector.getValue()));
}

Executor getExecutor() {
return executorInjector.getValue();
}
}
14 changes: 11 additions & 3 deletions jboss-integration/src/main/java/org/teiid/jboss/TeiidAdd.java
Expand Up @@ -45,6 +45,7 @@

import org.infinispan.manager.EmbeddedCacheManager;
import org.jboss.as.controller.AbstractAddStepHandler;
import org.jboss.as.controller.ModelController;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
Expand All @@ -62,6 +63,7 @@
import org.jboss.as.naming.service.BinderService;
import org.jboss.as.server.AbstractDeploymentChainStep;
import org.jboss.as.server.DeploymentProcessorTarget;
import org.jboss.as.server.Services;
import org.jboss.as.server.deployment.Phase;
import org.jboss.as.threads.ThreadFactoryResolver;
import org.jboss.as.threads.ThreadsServices;
Expand All @@ -75,11 +77,10 @@
import org.teiid.CommandContext;
import org.teiid.PolicyDecider;
import org.teiid.PreParser;
import org.teiid.adminapi.Admin;
import org.teiid.adminapi.jboss.AdminFactory;
import org.teiid.cache.CacheFactory;
import org.teiid.common.buffer.BufferManager;
import org.teiid.common.buffer.TupleBufferCache;
import org.teiid.deployers.RestWarGenerator;
import org.teiid.deployers.VDBRepository;
import org.teiid.deployers.VDBStatusChecker;
import org.teiid.dqp.internal.datamgr.TranslatorRepository;
Expand Down Expand Up @@ -562,7 +563,14 @@ public void start(StartContext context) throws StartException {

sessionServiceBuilder.install();


// rest war service
RestWarGenerator warGenerator= TeiidAdd.buildService(RestWarGenerator.class, "org.jboss.teiid.rest-service");
ResteasyEnabler restEnabler = new ResteasyEnabler(warGenerator);
ServiceBuilder<Void> warGeneratorSvc = target.addService(TeiidServiceNames.REST_WAR_SERVICE, restEnabler);
warGeneratorSvc.addDependency(Services.JBOSS_SERVER_CONTROLLER, ModelController.class, restEnabler.controllerValue);
warGeneratorSvc.addDependency(TeiidServiceNames.THREAD_POOL_SERVICE, Executor.class, restEnabler.executorInjector);
warGeneratorSvc.addDependency(TeiidServiceNames.VDB_REPO, VDBRepository.class, restEnabler.vdbRepoInjector);
warGeneratorSvc.install();
}

private void buildThreadService(int maxThreads, ServiceTarget target) {
Expand Down
Expand Up @@ -54,6 +54,7 @@ public class TeiidServiceNames {
public static ServiceName PREPAREDPLAN_CACHE_FACTORY = ServiceName.JBOSS.append("teiid", "infinispan-pp-cache-factory"); //$NON-NLS-1$ //$NON-NLS-2$
public static ServiceName MATVIEW_SERVICE = ServiceName.JBOSS.append("teiid", "matview-service"); //$NON-NLS-1$ //$NON-NLS-2$
public static ServiceName THREAD_POOL_SERVICE = ServiceName.JBOSS.append("teiid","teiid-async-threads"); //$NON-NLS-1$ //$NON-NLS-2$
public static ServiceName REST_WAR_SERVICE = ServiceName.JBOSS.append("teiid","teiid-rest-war-service"); //$NON-NLS-1$ //$NON-NLS-2$

public static class InvalidServiceNameException extends TeiidException {

Expand Down
17 changes: 10 additions & 7 deletions jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
Expand Up @@ -31,19 +31,25 @@

import javax.script.ScriptEngineManager;

import org.jboss.as.controller.ModelController;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.server.Services;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.modules.ModuleClassLoader;
import org.jboss.msc.service.*;
import org.jboss.msc.service.AbstractServiceListener;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceBuilder.DependencyType;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceController.Mode;
import org.jboss.msc.service.ServiceController.State;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
import org.jboss.vfs.VirtualFile;
import org.teiid.adminapi.Model;
Expand Down Expand Up @@ -191,10 +197,7 @@ public void deploy(final DeploymentPhaseContext context) throws DeploymentUnitP
vdbService.addDependency(TeiidServiceNames.VDB_STATUS_CHECKER, VDBStatusChecker.class, vdb.vdbStatusCheckInjector);
vdbService.addDependency(vdbSwitchServiceName, CountDownLatch.class, new InjectedValue<CountDownLatch>());
vdbService.addDependency(DependencyType.OPTIONAL, TeiidServiceNames.OBJECT_REPLICATOR, ObjectReplicator.class, vdb.objectReplicatorInjector);

// REST dependencies
vdbService.addDependency(Services.JBOSS_SERVER_CONTROLLER, ModelController.class, vdb.controllerValue);


// VDB restart switch, control the vdbservice by adding removing the switch service. If you
// remove the service by setting status remove, there is no way start it back up if vdbservice used alone
installVDBSwitchService(context.getServiceTarget(), vdbSwitchServiceName);
Expand Down
17 changes: 11 additions & 6 deletions jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
Expand Up @@ -34,7 +34,6 @@

import javax.xml.stream.XMLStreamException;

import org.jboss.as.controller.ModelController;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.msc.service.LifecycleContext;
import org.jboss.msc.service.Service;
Expand All @@ -55,7 +54,16 @@
import org.teiid.adminapi.impl.VDBMetadataParser;
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.common.buffer.BufferManager;
import org.teiid.deployers.*;
import org.teiid.deployers.CompositeGlobalTableStore;
import org.teiid.deployers.CompositeVDB;
import org.teiid.deployers.ContainerLifeCycleListener;
import org.teiid.deployers.RuntimeVDB;
import org.teiid.deployers.TranslatorUtil;
import org.teiid.deployers.UDFMetaData;
import org.teiid.deployers.VDBLifeCycleListener;
import org.teiid.deployers.VDBRepository;
import org.teiid.deployers.VDBStatusChecker;
import org.teiid.deployers.VirtualDatabaseException;
import org.teiid.dqp.internal.datamgr.ConnectorManager;
import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException;
Expand Down Expand Up @@ -85,10 +93,7 @@ class VDBService extends AbstractVDBDeployer implements Service<RuntimeVDB> {
protected final InjectedValue<BufferManager> bufferManagerInjector = new InjectedValue<BufferManager>();
protected final InjectedValue<ObjectReplicator> objectReplicatorInjector = new InjectedValue<ObjectReplicator>();
protected final InjectedValue<VDBStatusChecker> vdbStatusCheckInjector = new InjectedValue<VDBStatusChecker>();

// for REST deployment
protected final InjectedValue<ModelController> controllerValue = new InjectedValue<ModelController>();


private VDBLifeCycleListener vdbListener;
private VDBResources vdbResources;
private VDBKey vdbKey;
Expand Down
Expand Up @@ -560,4 +560,6 @@ TEIID50106=Deployment of {0} cannot proceed. There is another vdb with the same

TEIID50107=SSL configuration of transport {0} is invalid: {1}

TEIID50108=Failed to convert delegated credential to a subject, possibly ticket is invalid, turn on debug logging for more details.
TEIID50108=Failed to convert delegated credential to a subject, possibly ticket is invalid, turn on debug logging for more details.
TEIID50109= Failed to deploy {0}

Expand Up @@ -20,7 +20,9 @@
* 02110-1301 USA.
*/

package org.teiid.jboss.rest;
package org.teiid.jboss;

import java.util.concurrent.Executor;

import org.junit.Test;
import org.mockito.Mockito;
Expand All @@ -29,17 +31,25 @@
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.core.util.ExecutorUtils;
import org.teiid.deployers.CompositeVDB;
import org.teiid.deployers.ContainerLifeCycleListener;
import org.teiid.deployers.RestWarGenerator;
import org.teiid.deployers.TestCompositeVDB;
import org.teiid.deployers.VirtualDatabaseException;
import org.teiid.jboss.rest.ResteasyEnabler;
import org.teiid.metadata.MetadataStore;

@SuppressWarnings("nls")
public class TestResteasyEnabler {

@Test public void testOtherModels() throws VirtualDatabaseException {
ResteasyEnabler resteasyEnabler = new ResteasyEnabler(Mockito.mock(Admin.class), ExecutorUtils.getDirectExecutor());
RestWarGenerator generator = Mockito.mock(RestWarGenerator.class);
ResteasyEnabler resteasyEnabler = new ResteasyEnabler(generator) {
Admin getAdmin() {
return Mockito.mock(Admin.class);
}

Executor getExecutor() {
return ExecutorUtils.getDirectExecutor();
}
};

MetadataStore ms = new MetadataStore();

Expand Down

0 comments on commit f299ac3

Please sign in to comment.