use of org.jboss.as.server.deployment.DeploymentUnit in project fakereplace by fakereplace.
the class FakeReplaceServlet method doPost.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
ObjectInputStream in = new ObjectInputStream(req.getInputStream());
String deployment = in.readUTF();
ServiceController<DeploymentUnit> deploymentService = deploymentService(deployment);
Module module = deploymentService.getValue().getAttachment(Attachments.MODULE);
int size = in.readInt();
ClassDefinition[] definitions = new ClassDefinition[size];
for (int i = 0; i < size; ++i) {
String className = in.readUTF();
byte[] data = (byte[]) in.readObject();
Class clazz = module.getClassLoader().loadClass(className);
ClassDefinition d = new ClassDefinition(clazz, data);
definitions[i] = d;
}
size = in.readInt();
AddedClass[] added = new AddedClass[size];
for (int i = 0; i < size; ++i) {
String className = in.readUTF();
byte[] data = (byte[]) in.readObject();
added[i] = new AddedClass(className, data, module.getClassLoader());
}
size = in.readInt();
Map<String, byte[]> resources = new HashMap<>();
for (int i = 0; i < size; ++i) {
String resourceName = in.readUTF();
byte[] data = (byte[]) in.readObject();
resources.put(resourceName, data);
}
updateResource(resources, deploymentService);
Fakereplace.redefine(definitions, added);
} catch (ClassNotFoundException e) {
throw new ServletException(e);
}
}
use of org.jboss.as.server.deployment.DeploymentUnit in project teiid by teiid.
the class VDBDependencyDeployer method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!TeiidAttachments.isVDBDeployment(deploymentUnit)) {
return;
}
final VDBMetaData deployment = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
ArrayList<ModuleDependency> localDependencies = new ArrayList<ModuleDependency>();
ArrayList<ModuleDependency> userDependencies = new ArrayList<ModuleDependency>();
// $NON-NLS-1$
String moduleNames = deployment.getPropertyValue("lib");
if (moduleNames != null) {
StringTokenizer modules = new StringTokenizer(moduleNames);
while (modules.hasMoreTokens()) {
String moduleName = modules.nextToken().trim();
ModuleIdentifier lib = ModuleIdentifier.create(moduleName);
ModuleLoader moduleLoader = Module.getCallerModuleLoader();
try {
moduleLoader.loadModule(lib);
localDependencies.add(new ModuleDependency(moduleLoader, ModuleIdentifier.create(moduleName), false, false, false, false));
} catch (ModuleLoadException e) {
// this is to handle JAR based deployments which take on name like "deployment.<jar-name>"
moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
try {
moduleLoader.loadModule(lib);
userDependencies.add(new ModuleDependency(moduleLoader, ModuleIdentifier.create(moduleName), false, false, false, true));
} catch (ModuleLoadException e1) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50088, moduleName, deployment.getName(), deployment.getVersion(), e1));
}
}
}
}
if (!TeiidAttachments.isVDBXMLDeployment(deploymentUnit)) {
try {
final ResourceRoot deploymentResourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final VirtualFile deploymentRoot = deploymentResourceRoot.getRoot();
if (deploymentRoot == null) {
return;
}
final VirtualFile libDir = deploymentRoot.getChild(LIB);
if (libDir.exists()) {
final List<VirtualFile> archives = libDir.getChildren(DEFAULT_JAR_LIB_FILTER);
for (final VirtualFile archive : archives) {
try {
final Closeable closable = VFS.mountZip(archive, archive, TempFileProviderService.provider());
final ResourceRoot jarArchiveRoot = new ResourceRoot(archive.getName(), archive, new MountHandle(closable));
ModuleRootMarker.mark(jarArchiveRoot);
deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, jarArchiveRoot);
} catch (IOException e) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50018, archive), e);
}
}
}
} catch (IOException e) {
throw new DeploymentUnitProcessingException(e);
}
}
// add translators as dependent modules to this VDB.
try {
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
// $NON-NLS-1$
final ModuleLoader moduleLoader = Module.getCallerModule().getModule(ModuleIdentifier.create("org.jboss.teiid")).getModuleLoader();
// $NON-NLS-1$
moduleSpecification.addLocalDependency(new ModuleDependency(moduleLoader, ModuleIdentifier.create("org.jboss.teiid.api"), false, false, false, false));
// $NON-NLS-1$
moduleSpecification.addLocalDependency(new ModuleDependency(moduleLoader, ModuleIdentifier.create("org.jboss.teiid.common-core"), false, false, false, false));
// $NON-NLS-1$
moduleSpecification.addLocalDependency(new ModuleDependency(moduleLoader, ModuleIdentifier.create("javax.api"), false, false, false, false));
if (!localDependencies.isEmpty()) {
moduleSpecification.addLocalDependencies(localDependencies);
}
if (!userDependencies.isEmpty()) {
moduleSpecification.addUserDependencies(userDependencies);
}
} catch (ModuleLoadException e) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50018.name(), e);
}
}
use of org.jboss.as.server.deployment.DeploymentUnit in project teiid by teiid.
the class VDBDeployer method deploy.
public void deploy(final DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
if (!TeiidAttachments.isVDBDeployment(deploymentUnit)) {
return;
}
final VDBMetaData deployment = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
VDBMetaData other = this.vdbRepository.getVDB(deployment.getName(), deployment.getVersion());
if (other != null) {
String deploymentName = other.getPropertyValue(TranslatorUtil.DEPLOYMENT_NAME);
throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50106, deployment, deploymentName));
}
deployment.addProperty(TranslatorUtil.DEPLOYMENT_NAME, deploymentUnit.getName());
// check to see if there is old vdb already deployed.
final ServiceController<?> controller = context.getServiceRegistry().getService(TeiidServiceNames.vdbServiceName(deployment.getName(), deployment.getVersion()));
if (controller != null) {
LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50019, deployment));
controller.setMode(ServiceController.Mode.REMOVE);
}
boolean preview = deployment.isPreview();
if (!preview && deployment.hasErrors()) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50074, deployment));
}
// make sure the translator defined exists in configuration; otherwise add as error
for (ModelMetaData model : deployment.getModelMetaDatas().values()) {
if (!model.isSource() || model.getSourceNames().isEmpty()) {
continue;
}
for (String source : model.getSourceNames()) {
String translatorName = model.getSourceTranslatorName(source);
if (deployment.isOverideTranslator(translatorName)) {
VDBTranslatorMetaData parent = deployment.getTranslator(translatorName);
translatorName = parent.getType();
}
Translator translator = this.translatorRepository.getTranslatorMetaData(translatorName);
if (translator == null) {
String msg = IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50077, translatorName, deployment.getName(), deployment.getVersion());
LogManager.logWarning(LogConstants.CTX_RUNTIME, msg);
}
}
}
// add VDB module's classloader as an attachment
ModuleClassLoader classLoader = deploymentUnit.getAttachment(Attachments.MODULE).getClassLoader();
deployment.addAttchment(ClassLoader.class, classLoader);
deployment.addAttchment(ScriptEngineManager.class, new ScriptEngineManager(classLoader));
try {
EmbeddedServer.createPreParser(deployment);
} catch (TeiidException e1) {
throw new DeploymentUnitProcessingException(e1);
}
UDFMetaData udf = deploymentUnit.removeAttachment(TeiidAttachments.UDF_METADATA);
if (udf == null) {
udf = new UDFMetaData();
}
udf.setFunctionClassLoader(classLoader);
deployment.addAttchment(UDFMetaData.class, udf);
VirtualFile file = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
VDBResources resources;
try {
resources = new VDBResources(file, deployment);
} catch (IOException e) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
}
this.vdbRepository.addPendingDeployment(deployment);
// build a VDB service
final VDBService vdb = new VDBService(deployment, resources, shutdownListener);
// $NON-NLS-1$
vdb.addMetadataRepository("index", new IndexMetadataRepository());
final ServiceBuilder<RuntimeVDB> vdbService = context.getServiceTarget().addService(TeiidServiceNames.vdbServiceName(deployment.getName(), deployment.getVersion()), vdb);
// add dependencies to data-sources
dataSourceDependencies(deployment, context.getServiceTarget());
for (VDBImport vdbImport : deployment.getVDBImports()) {
VDBKey vdbKey = new VDBKey(vdbImport.getName(), vdbImport.getVersion());
if (vdbKey.isAtMost()) {
// TODO: could allow partial versions here if we canonicalize
throw new DeploymentUnitProcessingException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40144, deployment, vdbKey));
}
LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50115, deployment, vdbKey));
vdbService.addDependency(TeiidServiceNames.vdbFinishedServiceName(vdbImport.getName(), vdbKey.getVersion()));
}
// adding the translator services is redundant, however if one is removed then it is an issue.
for (Model model : deployment.getModels()) {
List<String> sourceNames = model.getSourceNames();
for (String sourceName : sourceNames) {
String translatorName = model.getSourceTranslatorName(sourceName);
if (deployment.isOverideTranslator(translatorName)) {
VDBTranslatorMetaData translator = deployment.getTranslator(translatorName);
translatorName = translator.getType();
}
vdbService.addDependency(TeiidServiceNames.translatorServiceName(translatorName));
}
}
ServiceName vdbSwitchServiceName = TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion());
vdbService.addDependency(TeiidServiceNames.VDB_REPO, VDBRepository.class, vdb.vdbRepositoryInjector);
vdbService.addDependency(TeiidServiceNames.TRANSLATOR_REPO, TranslatorRepository.class, vdb.translatorRepositoryInjector);
vdbService.addDependency(TeiidServiceNames.THREAD_POOL_SERVICE, Executor.class, vdb.executorInjector);
vdbService.addDependency(TeiidServiceNames.OBJECT_SERIALIZER, ObjectSerializer.class, vdb.serializerInjector);
vdbService.addDependency(TeiidServiceNames.VDB_STATUS_CHECKER, VDBStatusChecker.class, vdb.vdbStatusCheckInjector);
vdbService.addDependency(vdbSwitchServiceName, CountDownLatch.class, new InjectedValue<CountDownLatch>());
// 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);
vdbService.addListener(new AbstractServiceListener<Object>() {
@Override
public void transition(final ServiceController controller, final ServiceController.Transition transition) {
if (transition.equals(ServiceController.Transition.DOWN_to_WAITING)) {
RuntimeVDB runtimeVDB = RuntimeVDB.class.cast(controller.getValue());
if (runtimeVDB != null && runtimeVDB.isRestartInProgress()) {
ServiceName vdbSwitchServiceName = TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion());
ServiceController<?> switchSvc = controller.getServiceContainer().getService(vdbSwitchServiceName);
if (switchSvc != null) {
CountDownLatch latch = CountDownLatch.class.cast(switchSvc.getValue());
try {
latch.await(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// todo:log it?
}
}
installVDBSwitchService(controller.getServiceContainer(), vdbSwitchServiceName);
}
}
}
});
vdbService.setInitialMode(Mode.PASSIVE).install();
}
use of org.jboss.as.server.deployment.DeploymentUnit in project teiid by teiid.
the class TranslatorDeployer method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ServiceTarget target = phaseContext.getServiceTarget();
if (!TeiidAttachments.isTranslator(deploymentUnit)) {
return;
}
String moduleName = deploymentUnit.getName();
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
ClassLoader translatorLoader = module.getClassLoader();
final ServiceLoader<ExecutionFactory> serviceLoader = ServiceLoader.load(ExecutionFactory.class, translatorLoader);
if (serviceLoader != null) {
for (ExecutionFactory ef : serviceLoader) {
VDBTranslatorMetaData metadata = TranslatorUtil.buildTranslatorMetadata(ef, moduleName);
if (metadata == null) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50070, moduleName));
}
deploymentUnit.putAttachment(TeiidAttachments.TRANSLATOR_METADATA, metadata);
metadata.addProperty(TranslatorUtil.DEPLOYMENT_NAME, moduleName);
metadata.addAttchment(ClassLoader.class, translatorLoader);
LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50006, metadata.getName()));
buildService(target, metadata);
}
}
}
use of org.jboss.as.server.deployment.DeploymentUnit in project camunda-bpm-platform by camunda.
the class ProcessesXmlProcessor method deploy.
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!ProcessApplicationAttachments.isProcessApplication(deploymentUnit)) {
return;
}
final Module module = deploymentUnit.getAttachment(MODULE);
// read @ProcessApplication annotation of PA-component
String[] deploymentDescriptors = getDeploymentDescriptors(deploymentUnit);
// load all processes.xml files
List<URL> deploymentDescriptorURLs = getDeploymentDescriptorUrls(module, deploymentDescriptors);
for (URL processesXmlResource : deploymentDescriptorURLs) {
VirtualFile processesXmlFile = getFile(processesXmlResource);
// parse processes.xml metadata.
ProcessesXml processesXml = null;
if (isEmptyFile(processesXmlResource)) {
processesXml = ProcessesXml.EMPTY_PROCESSES_XML;
} else {
processesXml = parseProcessesXml(processesXmlResource);
}
// add the parsed metadata to the attachment list
ProcessApplicationAttachments.addProcessesXml(deploymentUnit, new ProcessesXmlWrapper(processesXml, processesXmlFile));
}
}
Aggregations