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());
}
}
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);
}
}
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);
}
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();
}
Aggregations