Search in sources :

Example 6 with ServiceController

use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.

the class NodeServiceServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String serviceName = getRequiredParameter(req, SERVICE);
    String expected = req.getParameter(EXPECTED);
    this.log(String.format("Received request for %s, expecting %s", serviceName, expected));
    @SuppressWarnings("unchecked") ServiceController<Node> service = (ServiceController<Node>) CurrentServiceContainer.getServiceContainer().getService(ServiceName.parse(serviceName));
    try {
        Node node = service.awaitValue();
        if (expected != null) {
            for (int i = 0; i < RETRIES; ++i) {
                if ((node != null) && expected.equals(node.getName()))
                    break;
                Thread.yield();
                node = service.awaitValue();
            }
        }
        if (node != null) {
            resp.setHeader(NODE_HEADER, node.getName());
        }
    } catch (IllegalStateException e) {
    // Thrown when quorum was not met
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    resp.getWriter().write("Success");
}
Also used : Node(org.wildfly.clustering.group.Node) ServiceController(org.jboss.msc.service.ServiceController)

Example 7 with ServiceController

use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.

the class AbstractUndertowSubsystemTestCase method testRuntime.

public static void testRuntime(KernelServices mainServices, final String virtualHostName, int flag) throws Exception {
    if (!mainServices.isSuccessfulBoot()) {
        Throwable t = mainServices.getBootError();
        Assert.fail("Boot unsuccessful: " + (t != null ? t.toString() : "no boot error provided"));
    }
    ServiceController<FilterService> connectionLimiter = (ServiceController<FilterService>) mainServices.getContainer().getService(UndertowService.FILTER.append("limit-connections"));
    connectionLimiter.setMode(ServiceController.Mode.ACTIVE);
    FilterService connectionLimiterService = connectionLimiter.getService().getValue();
    HttpHandler result = connectionLimiterService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
    Assert.assertNotNull("handler should have been created", result);
    ServiceController<FilterService> headersFilter = (ServiceController<FilterService>) mainServices.getContainer().getService(UndertowService.FILTER.append("headers"));
    headersFilter.setMode(ServiceController.Mode.ACTIVE);
    FilterService headersService = headersFilter.getService().getValue();
    HttpHandler headerHandler = headersService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
    Assert.assertNotNull("handler should have been created", headerHandler);
    final ServiceName hostServiceName = UndertowService.virtualHostName(virtualHostName, "other-host");
    ServiceController<Host> hostSC = (ServiceController<Host>) mainServices.getContainer().getService(hostServiceName);
    Assert.assertNotNull(hostSC);
    hostSC.setMode(ServiceController.Mode.ACTIVE);
    Host host = hostSC.getValue();
    Assert.assertEquals(1, host.getFilters().size());
    if (flag == 1) {
        Assert.assertEquals(3, host.getAllAliases().size());
        Assert.assertEquals("default-alias", new ArrayList<>(host.getAllAliases()).get(1));
    }
    final ServiceName locationServiceName = UndertowService.locationServiceName(virtualHostName, "default-host", "/");
    ServiceController<LocationService> locationSC = (ServiceController<LocationService>) mainServices.getContainer().getService(locationServiceName);
    Assert.assertNotNull(locationSC);
    locationSC.setMode(ServiceController.Mode.ACTIVE);
    LocationService locationService = locationSC.getValue();
    Assert.assertNotNull(locationService);
    connectionLimiter.setMode(ServiceController.Mode.REMOVE);
    final ServiceName jspServiceName = UndertowService.SERVLET_CONTAINER.append("myContainer");
    ServiceController<ServletContainerService> jspServiceServiceController = (ServiceController<ServletContainerService>) mainServices.getContainer().getService(jspServiceName);
    Assert.assertNotNull(jspServiceServiceController);
    JSPConfig jspConfig = jspServiceServiceController.getService().getValue().getJspConfig();
    Assert.assertNotNull(jspConfig);
    Assert.assertNotNull(jspConfig.createJSPServletInfo());
    final ServiceName filterRefName = UndertowService.filterRefName(virtualHostName, "other-host", "/", "static-gzip");
    ServiceController<FilterRef> gzipFilterController = (ServiceController<FilterRef>) mainServices.getContainer().getService(filterRefName);
    gzipFilterController.setMode(ServiceController.Mode.ACTIVE);
    FilterRef gzipFilterRef = gzipFilterController.getService().getValue();
    HttpHandler gzipHandler = gzipFilterRef.createHttpHandler(new PathHandler());
    Assert.assertNotNull("handler should have been created", gzipHandler);
}
Also used : HttpHandler(io.undertow.server.HttpHandler) FilterService(org.wildfly.extension.undertow.filters.FilterService) ArrayList(java.util.ArrayList) PathHandler(io.undertow.server.handlers.PathHandler) FilterRef(org.wildfly.extension.undertow.filters.FilterRef) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController)

Example 8 with ServiceController

use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.

the class AbstractUndertowSubsystemTestCase method testRuntimeLast.

public static void testRuntimeLast(KernelServices mainServices) {
    final ServiceName accessLogServiceName = UndertowService.accessLogServiceName("some-server", "default-host");
    ServiceController<AccessLogService> accessLogSC = (ServiceController<AccessLogService>) mainServices.getContainer().getService(accessLogServiceName);
    Assert.assertNotNull(accessLogSC);
    accessLogSC.setMode(ServiceController.Mode.ACTIVE);
    AccessLogService accessLogService = accessLogSC.getValue();
    Assert.assertNotNull(accessLogService);
    Assert.assertFalse(accessLogService.isRotate());
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController)

Example 9 with ServiceController

use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.

the class UndertowSubsystem12TestCase method testCustomFilters.

private void testCustomFilters(KernelServices mainServices) {
    ServiceController<FilterService> customFilter = (ServiceController<FilterService>) mainServices.getContainer().getService(UndertowService.FILTER.append("custom-filter"));
    customFilter.setMode(ServiceController.Mode.ACTIVE);
    FilterService connectionLimiterService = customFilter.getService().getValue();
    HttpHandler result = connectionLimiterService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
    Assert.assertNotNull("handler should have been created", result);
}
Also used : HttpHandler(io.undertow.server.HttpHandler) FilterService(org.wildfly.extension.undertow.filters.FilterService) PathHandler(io.undertow.server.handlers.PathHandler) ServiceController(org.jboss.msc.service.ServiceController)

Example 10 with ServiceController

use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.

the class WSEndpointMetrics method getEndpointMetricsFragment.

@SuppressWarnings("unchecked")
private ModelNode getEndpointMetricsFragment(final ModelNode operation, final ServiceRegistry registry) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    String endpointId;
    try {
        endpointId = URLDecoder.decode(address.getLastElement().getValue(), "UTF-8");
    } catch (final UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
    final String metricName = operation.require(NAME).asString();
    final String webContext = endpointId.substring(0, endpointId.indexOf(":"));
    final String endpointName = endpointId.substring(endpointId.indexOf(":") + 1);
    ServiceName endpointServiceName = WSServices.ENDPOINT_SERVICE.append("context=" + webContext).append(endpointName);
    ServiceController<Endpoint> service = (ServiceController<Endpoint>) currentServiceContainer().getService(endpointServiceName);
    Endpoint endpoint = service.getValue();
    if (endpoint == null) {
        throw new OperationFailedException(WSLogger.ROOT_LOGGER.noMetricsAvailable());
    }
    final ModelNode result = new ModelNode();
    final EndpointMetrics endpointMetrics = endpoint.getEndpointMetrics();
    if (MIN_PROCESSING_TIME.getName().equals(metricName)) {
        result.set(endpointMetrics.getMinProcessingTime());
    } else if (MAX_PROCESSING_TIME.getName().equals(metricName)) {
        result.set(endpointMetrics.getMaxProcessingTime());
    } else if (AVERAGE_PROCESSING_TIME.getName().equals(metricName)) {
        result.set(endpointMetrics.getAverageProcessingTime());
    } else if (TOTAL_PROCESSING_TIME.getName().equals(metricName)) {
        result.set(endpointMetrics.getTotalProcessingTime());
    } else if (REQUEST_COUNT.getName().equals(metricName)) {
        result.set(endpointMetrics.getRequestCount());
    } else if (RESPONSE_COUNT.getName().equals(metricName)) {
        result.set(endpointMetrics.getResponseCount());
    } else if (FAULT_COUNT.getName().equals(metricName)) {
        result.set(endpointMetrics.getFaultCount());
    }
    return result;
}
Also used : Endpoint(org.jboss.wsf.spi.deployment.Endpoint) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode) EndpointMetrics(org.jboss.wsf.spi.management.EndpointMetrics)

Aggregations

ServiceController (org.jboss.msc.service.ServiceController)51 ServiceName (org.jboss.msc.service.ServiceName)20 ModelNode (org.jboss.dmr.ModelNode)17 OperationFailedException (org.jboss.as.controller.OperationFailedException)15 OperationContext (org.jboss.as.controller.OperationContext)12 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)12 BinderService (org.jboss.as.naming.service.BinderService)9 PathAddress (org.jboss.as.controller.PathAddress)8 ContextNames (org.jboss.as.naming.deployment.ContextNames)8 HttpHandler (io.undertow.server.HttpHandler)7 PathHandler (io.undertow.server.handlers.PathHandler)7 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)7 FilterService (org.wildfly.extension.undertow.filters.FilterService)7 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)6 ArrayList (java.util.ArrayList)5 Resource (org.jboss.as.controller.registry.Resource)5 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)5 AbstractServiceListener (org.jboss.msc.service.AbstractServiceListener)5 List (java.util.List)4 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)4