Search in sources :

Example 1 with PathManager

use of org.jboss.as.controller.services.path.PathManager in project wildfly by wildfly.

the class ExportJournalOperation method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (context.getRunningMode() != ADMIN_ONLY) {
        throw MessagingLogger.ROOT_LOGGER.managementOperationAllowedOnlyInRunningMode("export-journal", ADMIN_ONLY);
    }
    final ServiceController<PathManager> service = (ServiceController<PathManager>) context.getServiceRegistry(false).getService(PathManagerService.SERVICE_NAME);
    final PathManager pathManager = service.getService().getValue();
    final String journal = resolvePath(context, pathManager, JOURNAL_DIRECTORY_PATH);
    final String bindings = resolvePath(context, pathManager, BINDINGS_DIRECTORY_PATH);
    final String paging = resolvePath(context, pathManager, PAGING_DIRECTORY_PATH);
    final String largeMessages = resolvePath(context, pathManager, LARGE_MESSAGES_DIRECTORY_PATH);
    final XmlDataExporter exporter = new XmlDataExporter();
    String name = String.format(FILE_NAME_FORMAT, new Date());
    // write the exported dump at the same level than the journal directory
    File dump = new File(new File(journal).getParent(), name);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(dump);
        exporter.process(fos, bindings, journal, paging, largeMessages);
        context.getResult().set(dump.getAbsolutePath());
    } catch (Exception e) {
        throw new OperationFailedException(e);
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : PathManager(org.jboss.as.controller.services.path.PathManager) FileOutputStream(java.io.FileOutputStream) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceController(org.jboss.msc.service.ServiceController) IOException(java.io.IOException) File(java.io.File) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.XmlDataExporter) Date(java.util.Date) IOException(java.io.IOException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 2 with PathManager

use of org.jboss.as.controller.services.path.PathManager in project wildfly by wildfly.

the class EJB3Extension method initialize.

/**
     * {@inheritDoc}
     */
@Override
public void initialize(ExtensionContext context) {
    final boolean registerRuntimeOnly = context.isRuntimeOnlyRegistrationValid();
    final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION);
    subsystem.registerXMLElementWriter(EJB3SubsystemXMLPersister.INSTANCE);
    PathManager pathManager = context.getProcessType().isServer() ? context.getPathManager() : null;
    subsystem.registerSubsystemModel(new EJB3SubsystemRootResourceDefinition(registerRuntimeOnly, pathManager));
    if (registerRuntimeOnly) {
        ResourceDefinition deploymentsDef = new SimpleResourceDefinition(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, SUBSYSTEM_NAME), getResourceDescriptionResolver("deployed"));
        final ManagementResourceRegistration deploymentsRegistration = subsystem.registerDeploymentModel(deploymentsDef);
        deploymentsRegistration.registerSubModel(MessageDrivenBeanResourceDefinition.INSTANCE);
        deploymentsRegistration.registerSubModel(SingletonBeanDeploymentResourceDefinition.INSTANCE);
        deploymentsRegistration.registerSubModel(StatelessSessionBeanDeploymentResourceDefinition.INSTANCE);
        deploymentsRegistration.registerSubModel(StatefulSessionBeanDeploymentResourceDefinition.INSTANCE);
    }
    // Transformers
    if (context.isRegisterTransformers()) {
        EJB3SubsystemRootResourceDefinition.registerTransformers(subsystem);
    }
}
Also used : PathManager(org.jboss.as.controller.services.path.PathManager) StatelessSessionBeanDeploymentResourceDefinition(org.jboss.as.ejb3.subsystem.deployment.StatelessSessionBeanDeploymentResourceDefinition) SimpleResourceDefinition(org.jboss.as.controller.SimpleResourceDefinition) SingletonBeanDeploymentResourceDefinition(org.jboss.as.ejb3.subsystem.deployment.SingletonBeanDeploymentResourceDefinition) ResourceDefinition(org.jboss.as.controller.ResourceDefinition) MessageDrivenBeanResourceDefinition(org.jboss.as.ejb3.subsystem.deployment.MessageDrivenBeanResourceDefinition) StatefulSessionBeanDeploymentResourceDefinition(org.jboss.as.ejb3.subsystem.deployment.StatefulSessionBeanDeploymentResourceDefinition) SimpleResourceDefinition(org.jboss.as.controller.SimpleResourceDefinition) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) SubsystemRegistration(org.jboss.as.controller.SubsystemRegistration)

Example 3 with PathManager

use of org.jboss.as.controller.services.path.PathManager in project wildfly by wildfly.

the class WarStructureDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        // Skip non web deployments
        return;
    }
    final ResourceRoot deploymentResourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile deploymentRoot = deploymentResourceRoot.getRoot();
    if (deploymentRoot == null) {
        return;
    }
    // set the child first behaviour
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    if (moduleSpecification == null) {
        return;
    }
    moduleSpecification.setPrivateModule(true);
    // other sub deployments should not have access to classes in the war module
    PrivateSubDeploymentMarker.mark(deploymentUnit);
    // OSGi WebApp deployments (WAB) may use the deployment root if they don't use WEB-INF/classes already
    if (!deploymentUnit.hasAttachment(Attachments.OSGI_MANIFEST) || deploymentRoot.getChild(WEB_INF_CLASSES).exists()) {
        // we do not want to index the resource root, only WEB-INF/classes and WEB-INF/lib
        deploymentResourceRoot.putAttachment(Attachments.INDEX_RESOURCE_ROOT, false);
        // Make sure the root does not end up in the module, only META-INF
        deploymentResourceRoot.getExportFilters().add(new FilterSpecification(PathFilters.getMetaInfFilter(), true));
        deploymentResourceRoot.getExportFilters().add(new FilterSpecification(PathFilters.getMetaInfSubdirectoriesFilter(), true));
        deploymentResourceRoot.getExportFilters().add(new FilterSpecification(PathFilters.acceptAll(), false));
        ModuleRootMarker.mark(deploymentResourceRoot, true);
    }
    // TODO: This needs to be ported to add additional resource roots the standard way
    final MountHandle mountHandle = deploymentResourceRoot.getMountHandle();
    try {
        // add standard resource roots, this should eventually replace ClassPathEntry
        final List<ResourceRoot> resourceRoots = createResourceRoots(deploymentRoot, deploymentUnit);
        for (ResourceRoot root : resourceRoots) {
            deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, root);
        }
    } catch (Exception e) {
        throw new DeploymentUnitProcessingException(e);
    }
    // Add the war metadata
    final WarMetaData warMetaData = new WarMetaData();
    deploymentUnit.putAttachment(WarMetaData.ATTACHMENT_KEY, warMetaData);
    String deploymentName;
    if (deploymentUnit.getParent() == null) {
        deploymentName = deploymentUnit.getName();
    } else {
        deploymentName = deploymentUnit.getParent().getName() + "." + deploymentUnit.getName();
    }
    PathManager pathManager = deploymentUnit.getAttachment(Attachments.PATH_MANAGER);
    File tempDir = new File(pathManager.getPathEntry(TEMP_DIR).resolvePath(), deploymentName);
    tempDir.mkdirs();
    warMetaData.setTempDir(tempDir);
    moduleSpecification.addPermissionFactory(new ImmediatePermissionFactory(new FilePermission(tempDir.getAbsolutePath() + File.separatorChar + "-", "read,write,delete")));
    // Add the shared TLDs metadata
    final TldsMetaData tldsMetaData = new TldsMetaData();
    tldsMetaData.setSharedTlds(sharedTldsMetaData);
    deploymentUnit.putAttachment(TldsMetaData.ATTACHMENT_KEY, tldsMetaData);
    processExternalMounts(deploymentUnit, deploymentRoot);
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) PathManager(org.jboss.as.controller.services.path.PathManager) MountHandle(org.jboss.as.server.deployment.module.MountHandle) FilterSpecification(org.jboss.as.server.deployment.module.FilterSpecification) WarMetaData(org.jboss.as.web.common.WarMetaData) FilePermission(java.io.FilePermission) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) IOException(java.io.IOException) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) ImmediatePermissionFactory(org.jboss.modules.security.ImmediatePermissionFactory) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File)

Example 4 with PathManager

use of org.jboss.as.controller.services.path.PathManager in project wildfly by wildfly.

the class ActiveMQServerService method start.

public synchronized void start(final StartContext context) throws StartException {
    ClassLoader origTCCL = org.wildfly.security.manager.WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    // Validate whether the AIO native layer can be used
    JournalType jtype = configuration.getJournalType();
    if (jtype == JournalType.ASYNCIO) {
        boolean supportsAIO = AIOSequentialFileFactory.isSupported();
        if (supportsAIO == false) {
            String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
            if (osName.contains("nux")) {
                ROOT_LOGGER.aioInfoLinux();
            } else {
                ROOT_LOGGER.aioInfo();
            }
            configuration.setJournalType(JournalType.NIO);
        }
    }
    // Setup paths
    PathManager pathManager = this.pathManager.getValue();
    configuration.setBindingsDirectory(pathConfig.resolveBindingsPath(pathManager));
    configuration.setLargeMessagesDirectory(pathConfig.resolveLargeMessagePath(pathManager));
    configuration.setJournalDirectory(pathConfig.resolveJournalPath(pathManager));
    configuration.setPagingDirectory(pathConfig.resolvePagingPath(pathManager));
    pathConfig.registerCallbacks(pathManager);
    try {
        // Update the acceptor/connector port/host values from the
        // Map the socket bindings onto the connectors/acceptors
        Collection<TransportConfiguration> acceptors = configuration.getAcceptorConfigurations();
        Collection<TransportConfiguration> connectors = configuration.getConnectorConfigurations().values();
        Collection<BroadcastGroupConfiguration> broadcastGroups = configuration.getBroadcastGroupConfigurations();
        Map<String, DiscoveryGroupConfiguration> discoveryGroups = configuration.getDiscoveryGroupConfigurations();
        if (connectors != null) {
            for (TransportConfiguration tc : connectors) {
                // If there is a socket binding set the HOST/PORT values
                Object socketRef = tc.getParams().remove(SOCKET_REF);
                if (socketRef != null) {
                    String name = socketRef.toString();
                    String host;
                    int port;
                    OutboundSocketBinding binding = outboundSocketBindings.get(name);
                    if (binding == null) {
                        final SocketBinding socketBinding = socketBindings.get(name);
                        if (socketBinding == null) {
                            throw MessagingLogger.ROOT_LOGGER.failedToFindConnectorSocketBinding(tc.getName());
                        }
                        InetSocketAddress sa = socketBinding.getSocketAddress();
                        port = sa.getPort();
                        // resolve the host name of the address only if a loopback address has been set
                        if (sa.getAddress().isLoopbackAddress()) {
                            host = NetworkUtils.canonize(sa.getAddress().getHostName());
                        } else {
                            host = NetworkUtils.canonize(sa.getAddress().getHostAddress());
                        }
                    } else {
                        port = binding.getDestinationPort();
                        host = NetworkUtils.canonize(binding.getUnresolvedDestinationAddress());
                        if (binding.getSourceAddress() != null) {
                            tc.getParams().put(TransportConstants.LOCAL_ADDRESS_PROP_NAME, NetworkUtils.canonize(binding.getSourceAddress().getHostAddress()));
                        }
                        if (binding.getSourcePort() != null) {
                            // Use absolute port to account for source port offset/fixation
                            tc.getParams().put(TransportConstants.LOCAL_PORT_PROP_NAME, binding.getAbsoluteSourcePort());
                        }
                    }
                    tc.getParams().put(HOST, host);
                    tc.getParams().put(PORT, port);
                }
            }
        }
        if (acceptors != null) {
            for (TransportConfiguration tc : acceptors) {
                // If there is a socket binding set the HOST/PORT values
                Object socketRef = tc.getParams().remove(SOCKET_REF);
                if (socketRef != null) {
                    String name = socketRef.toString();
                    SocketBinding binding = socketBindings.get(name);
                    if (binding == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindConnectorSocketBinding(tc.getName());
                    }
                    binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
                    InetSocketAddress socketAddress = binding.getSocketAddress();
                    tc.getParams().put(HOST, socketAddress.getAddress().getHostAddress());
                    tc.getParams().put(PORT, socketAddress.getPort());
                }
            }
        }
        if (broadcastGroups != null) {
            final List<BroadcastGroupConfiguration> newConfigs = new ArrayList<BroadcastGroupConfiguration>();
            for (final BroadcastGroupConfiguration config : broadcastGroups) {
                final String name = config.getName();
                final String key = "broadcast" + name;
                if (jgroupFactories.containsKey(key)) {
                    ChannelFactory channelFactory = jgroupFactories.get(key);
                    String channelName = jgroupsChannels.get(key);
                    JChannel channel = (JChannel) channelFactory.createChannel(channelName);
                    channels.put(channelName, channel);
                    newConfigs.add(BroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, channel, channelName));
                } else {
                    final SocketBinding binding = groupBindings.get(key);
                    if (binding == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindBroadcastSocketBinding(name);
                    }
                    binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
                    newConfigs.add(BroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, binding));
                }
            }
            configuration.getBroadcastGroupConfigurations().clear();
            configuration.getBroadcastGroupConfigurations().addAll(newConfigs);
        }
        if (discoveryGroups != null) {
            configuration.setDiscoveryGroupConfigurations(new HashMap<String, DiscoveryGroupConfiguration>());
            for (final Map.Entry<String, DiscoveryGroupConfiguration> entry : discoveryGroups.entrySet()) {
                final String name = entry.getKey();
                final String key = "discovery" + name;
                DiscoveryGroupConfiguration config = null;
                if (jgroupFactories.containsKey(key)) {
                    ChannelFactory channelFactory = jgroupFactories.get(key);
                    String channelName = jgroupsChannels.get(key);
                    JChannel channel = channels.get(channelName);
                    if (channel == null) {
                        channel = (JChannel) channelFactory.createChannel(key);
                        channels.put(channelName, channel);
                    }
                    config = DiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), channel, channelName);
                } else {
                    final SocketBinding binding = groupBindings.get(key);
                    if (binding == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindDiscoverySocketBinding(name);
                    }
                    config = DiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), binding);
                    binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
                }
                configuration.getDiscoveryGroupConfigurations().put(name, config);
            }
        }
        // security - if an Elytron domain has been defined we delegate security checks to the Elytron based security manager.
        ActiveMQSecurityManager securityManager = null;
        final SecurityDomain elytronDomain = this.elytronSecurityDomain.getOptionalValue();
        if (elytronDomain != null) {
            securityManager = new ElytronSecurityManager(elytronDomain);
        } else {
            securityManager = new WildFlySecurityManager(securityDomainContextValue.getValue());
        }
        // insert possible credential source hold passwords
        setBridgePasswordsFromCredentialSource();
        setClusterPasswordFromCredentialSource();
        DataSource ds = dataSource.getOptionalValue();
        if (ds != null) {
            DatabaseStorageConfiguration dbConfiguration = (DatabaseStorageConfiguration) configuration.getStoreConfiguration();
            dbConfiguration.setDataSource(ds);
            // inject the datasource into the PropertySQLProviderFactory to be able to determine the
            // type of database for the datasource metadata
            PropertySQLProviderFactory sqlProviderFactory = (PropertySQLProviderFactory) dbConfiguration.getSqlProviderFactory();
            sqlProviderFactory.investigateDialect(ds);
            configuration.setStoreConfiguration(dbConfiguration);
            ROOT_LOGGER.infof("use JDBC store for Artemis server, bindingsTable:%s", dbConfiguration.getBindingsTableName());
        }
        // Now start the server
        server = new ActiveMQServerImpl(configuration, mbeanServer.getOptionalValue(), securityManager);
        if (ActiveMQDefaultConfiguration.getDefaultClusterPassword().equals(server.getConfiguration().getClusterPassword())) {
            server.getConfiguration().setClusterPassword(java.util.UUID.randomUUID().toString());
        }
        for (Interceptor incomingInterceptor : incomingInterceptors) {
            server.getServiceRegistry().addIncomingInterceptor(incomingInterceptor);
        }
        for (Interceptor outgoingInterceptor : outgoingInterceptors) {
            server.getServiceRegistry().addOutgoingInterceptor(outgoingInterceptor);
        }
    // the server is actually started by the JMSService.
    } catch (Exception e) {
        throw MessagingLogger.ROOT_LOGGER.failedToStartService(e);
    } finally {
        org.wildfly.security.manager.WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(origTCCL);
    }
}
Also used : OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) SocketBinding(org.jboss.as.network.SocketBinding) JChannel(org.jgroups.JChannel) OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) BroadcastGroupConfiguration(org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration) ActiveMQSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager) Interceptor(org.apache.activemq.artemis.api.core.Interceptor) PathManager(org.jboss.as.controller.services.path.PathManager) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) StartException(org.jboss.msc.service.StartException) DataSource(javax.sql.DataSource) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) JournalType(org.apache.activemq.artemis.core.server.JournalType) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

PathManager (org.jboss.as.controller.services.path.PathManager)4 File (java.io.File)2 IOException (java.io.IOException)2 FileOutputStream (java.io.FileOutputStream)1 FilePermission (java.io.FilePermission)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DataSource (javax.sql.DataSource)1 BroadcastGroupConfiguration (org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration)1 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)1 Interceptor (org.apache.activemq.artemis.api.core.Interceptor)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 XmlDataExporter (org.apache.activemq.artemis.cli.commands.tools.XmlDataExporter)1 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)1 JournalType (org.apache.activemq.artemis.core.server.JournalType)1 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)1 ActiveMQSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager)1