Search in sources :

Example 1 with BLogManager

use of org.ballerinalang.logging.BLogManager in project ballerina by ballerina-lang.

the class HTTPServicesRegistry method registerService.

/**
 * Register a service into the map.
 *
 * @param service requested serviceInfo to be registered.
 */
public void registerService(Service service) {
    String accessLogConfig = HttpConnectionManager.getInstance().getHttpAccessLoggerConfig();
    if (accessLogConfig != null) {
        try {
            ((BLogManager) BLogManager.getLogManager()).setHttpAccessLogHandler(accessLogConfig);
        } catch (IOException e) {
            throw new BallerinaConnectorException("Invalid file path: " + accessLogConfig, e);
        }
    }
    HttpService httpService = HttpService.buildHttpService(service);
    // TODO check with new method
    // HttpUtil.populateKeepAliveAndCompressionStatus(service, annotation);
    // TODO: Add websocket services to the service registry when service creation get available.
    servicesInfoMap.put(httpService.getBasePath(), httpService);
    logger.info("Service deployed : " + service.getName() + " with context " + httpService.getBasePath());
    // basePath will get cached after registering service
    sortedServiceURIs.add(httpService.getBasePath());
    sortedServiceURIs.sort((basePath1, basePath2) -> basePath2.length() - basePath1.length());
    // If WebSocket upgrade path is available, then register the name of the WebSocket service.
    Struct websocketConfig = httpService.getWebSocketUpgradeConfig();
    if (websocketConfig != null) {
        registerWebSocketUpgradePath(WebSocketUtil.getProgramFile(httpService.getBallerinaService().getResources()[0]), websocketConfig, httpService.getBasePath());
    }
}
Also used : BLogManager(org.ballerinalang.logging.BLogManager) BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) IOException(java.io.IOException) Struct(org.ballerinalang.connector.api.Struct)

Example 2 with BLogManager

use of org.ballerinalang.logging.BLogManager in project ballerina by ballerina-lang.

the class LauncherUtils method runProgram.

public static void runProgram(Path sourceRootPath, Path sourcePath, boolean runServices, Map<String, String> runtimeParams, String configFilePath, String[] args, boolean offline) {
    ProgramFile programFile;
    String srcPathStr = sourcePath.toString();
    Path fullPath = sourceRootPath.resolve(sourcePath);
    if (srcPathStr.endsWith(BLangConstants.BLANG_EXEC_FILE_SUFFIX)) {
        programFile = BLangProgramLoader.read(sourcePath);
    } else if (Files.isRegularFile(fullPath) && srcPathStr.endsWith(BLangConstants.BLANG_SRC_FILE_SUFFIX) && !Files.isDirectory(sourceRootPath.resolve(DOT_BALLERINA_DIR_NAME))) {
        programFile = compile(fullPath.getParent(), fullPath.getFileName(), offline);
    } else if (Files.isDirectory(sourceRootPath)) {
        programFile = compile(sourceRootPath, sourcePath, offline);
    } else {
        throw new BallerinaException("Invalid Ballerina source path, it should either be a directory or a file " + "with a \'" + BLangConstants.BLANG_SRC_FILE_SUFFIX + "\' extension.");
    }
    // If there is no main or service entry point, throw an error
    if (!programFile.isMainEPAvailable() && !programFile.isServiceEPAvailable()) {
        throw new RuntimeException("main function not found in '" + programFile.getProgramFilePath() + "'");
    }
    Path ballerinaConfPath = sourceRootPath.resolve("ballerina.conf");
    try {
        ConfigRegistry.getInstance().initRegistry(runtimeParams, configFilePath, ballerinaConfPath);
        ((BLogManager) LogManager.getLogManager()).loadUserProvidedLogConfiguration();
    } catch (IOException e) {
        throw new RuntimeException("failed to read the specified configuration file: " + ballerinaConfPath.toString(), e);
    }
    if (runServices || !programFile.isMainEPAvailable()) {
        if (args.length > 0) {
            throw LauncherUtils.createUsageException("too many arguments");
        }
        runServices(programFile);
    } else {
        runMain(programFile, args);
    }
}
Also used : Path(java.nio.file.Path) BLogManager(org.ballerinalang.logging.BLogManager) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) IOException(java.io.IOException) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Example 3 with BLogManager

use of org.ballerinalang.logging.BLogManager in project ballerina by ballerina-lang.

the class TestCmd method execute.

public void execute() {
    if (helpFlag) {
        printCommandUsageInfo(parentCmdParser, "test");
        return;
    }
    if (sourceFileList == null || sourceFileList.isEmpty()) {
        Path userDir = Paths.get(System.getProperty("user.dir"));
        SourceDirectory srcDirectory = new FileSystemProjectDirectory(userDir);
        sourceFileList = srcDirectory.getSourcePackageNames();
    }
    if (groupList != null && disableGroupList != null) {
        throw LauncherUtils.createUsageException("Cannot specify both --groups and --disable-groups flags at the same time");
    }
    Path sourceRootPath = LauncherUtils.getSourceRootPath(sourceRoot);
    Path ballerinaConfPath = sourceRootPath.resolve("ballerina.conf");
    try {
        ConfigRegistry.getInstance().initRegistry(configRuntimeParams, null, ballerinaConfPath);
        ((BLogManager) LogManager.getLogManager()).loadUserProvidedLogConfiguration();
    } catch (IOException e) {
        throw new RuntimeException("failed to read the specified configuration file: " + ballerinaConfPath.toString(), e);
    }
    Path[] paths = sourceFileList.stream().map(Paths::get).toArray(Path[]::new);
    BTestRunner testRunner = new BTestRunner();
    if (disableGroupList != null) {
        testRunner.runTest(sourceRoot, paths, disableGroupList, false);
    } else {
        testRunner.runTest(sourceRoot, paths, groupList, true);
    }
    if (testRunner.getTesterinaReport().isFailure()) {
        Runtime.getRuntime().exit(1);
    }
    Runtime.getRuntime().exit(0);
}
Also used : Path(java.nio.file.Path) BLogManager(org.ballerinalang.logging.BLogManager) FileSystemProjectDirectory(org.wso2.ballerinalang.compiler.FileSystemProjectDirectory) SourceDirectory(org.wso2.ballerinalang.compiler.SourceDirectory) IOException(java.io.IOException)

Example 4 with BLogManager

use of org.ballerinalang.logging.BLogManager in project ballerina by ballerina-lang.

the class StartWebSubSubscriberServiceEndpoint method execute.

@Override
public void execute(Context context) {
    Struct subscriberServiceEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
    Struct serviceEndpoint = ConnectorSPIModelHelper.createStruct((BStruct) ((BStruct) (subscriberServiceEndpoint.getVMValue())).getRefField(1));
    ServerConnector serverConnector = getServerConnector(serviceEndpoint);
    if (isHTTPTraceLoggerEnabled()) {
        try {
            ((BLogManager) BLogManager.getLogManager()).setHttpTraceLogHandler();
        } catch (IOException e) {
            throw new BallerinaConnectorException("Invalid HTTP trace log parameters found.", e);
        } catch (TraceLogConfigurationException e) {
            throw new BallerinaConnectorException("Unsupported HTTP trace log configuration. " + e.getMessage(), e);
        }
    }
    ServerConnectorFuture serverConnectorFuture = serverConnector.start();
    WebSubServicesRegistry webSubServicesRegistry = (WebSubServicesRegistry) serviceEndpoint.getNativeData(WebSubSubscriberConstants.WEBSUB_SERVICE_REGISTRY);
    HashSet<FilterHolder> filterHolder = getFilters(serviceEndpoint);
    serverConnectorFuture.setHttpConnectorListener(new BallerinaWebSubConnectionListener(webSubServicesRegistry, filterHolder));
    serverConnectorFuture.setPortBindingEventListener(new HttpConnectorPortBindingListener());
    context.setReturnValues();
}
Also used : BLogManager(org.ballerinalang.logging.BLogManager) BStruct(org.ballerinalang.model.values.BStruct) BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) FilterHolder(org.ballerinalang.net.http.serviceendpoint.FilterHolder) HttpConnectorPortBindingListener(org.ballerinalang.net.http.HttpConnectorPortBindingListener) ServerConnectorFuture(org.wso2.transport.http.netty.contract.ServerConnectorFuture) BallerinaWebSubConnectionListener(org.ballerinalang.net.websub.BallerinaWebSubConnectionListener) IOException(java.io.IOException) BStruct(org.ballerinalang.model.values.BStruct) Struct(org.ballerinalang.connector.api.Struct) ServerConnector(org.wso2.transport.http.netty.contract.ServerConnector) TraceLogConfigurationException(org.ballerinalang.logging.exceptions.TraceLogConfigurationException) WebSubServicesRegistry(org.ballerinalang.net.websub.WebSubServicesRegistry)

Aggregations

IOException (java.io.IOException)4 BLogManager (org.ballerinalang.logging.BLogManager)4 Path (java.nio.file.Path)2 BallerinaConnectorException (org.ballerinalang.connector.api.BallerinaConnectorException)2 Struct (org.ballerinalang.connector.api.Struct)2 TraceLogConfigurationException (org.ballerinalang.logging.exceptions.TraceLogConfigurationException)1 BStruct (org.ballerinalang.model.values.BStruct)1 HttpConnectorPortBindingListener (org.ballerinalang.net.http.HttpConnectorPortBindingListener)1 FilterHolder (org.ballerinalang.net.http.serviceendpoint.FilterHolder)1 BallerinaWebSubConnectionListener (org.ballerinalang.net.websub.BallerinaWebSubConnectionListener)1 WebSubServicesRegistry (org.ballerinalang.net.websub.WebSubServicesRegistry)1 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)1 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)1 FileSystemProjectDirectory (org.wso2.ballerinalang.compiler.FileSystemProjectDirectory)1 SourceDirectory (org.wso2.ballerinalang.compiler.SourceDirectory)1 ServerConnector (org.wso2.transport.http.netty.contract.ServerConnector)1 ServerConnectorFuture (org.wso2.transport.http.netty.contract.ServerConnectorFuture)1