Skip to content

Commit

Permalink
Merge pull request #1785 from senthuran16/siddhi-extensions-installer
Browse files Browse the repository at this point in the history
Add Siddhi Extensions Installer Backend
  • Loading branch information
dnwick authored Feb 14, 2020
2 parents c42622b + ef2c714 commit 50fcb48
Show file tree
Hide file tree
Showing 28 changed files with 1,984 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
# Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-->

<FindBugsFilter>
<!-- Filters out model classes used for config mapping, that do not have setters, but are written by Gson -->
<Match>
<Package name="org.wso2.carbon.siddhi.extensions.installer.core.config.mapping.models"/>
<Bug pattern="UWF_UNWRITTEN_FIELD"/>
</Match>
</FindBugsFilter>
121 changes: 121 additions & 0 deletions components/org.wso2.carbon.siddhi.extensions.installer.core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
# Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.wso2.carbon.analytics</groupId>
<artifactId>org.wso2.carbon.analytics.parent</artifactId>
<version>3.0.25-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.siddhi.extensions.installer.core</artifactId>
<packaging>bundle</packaging>

<name>WSO2 Streaming Integrator - Siddhi Extensions Installer Core</name>
<url>http://wso2.org</url>

<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi.services</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.msf4j</groupId>
<artifactId>msf4j-core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.utils</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
</dependency>
<dependency>
<groupId>commons-io.wso2</groupId>
<artifactId>commons-io</artifactId>
</dependency>
</dependencies>

<properties>
<maven.findbugsplugin.version.exclude>findbugs-exclude.xml</maven.findbugsplugin.version.exclude>
<private.package>
org.wso2.carbon.siddhi.extensions.installer.core.internal,
org.wso2.carbon.siddhi.extensions.installer.core.internal.*,
</private.package>
<export.package>
org.wso2.carbon.siddhi.extensions.installer.core.*
</export.package>
<import.package>
com.google.gson; version="${gson.version.range}",
com.google.gson.reflect; version="${gson.version.range}",
javax.ws.rs;version="${javax.ws.rs.version.range}",
javax.ws.rs.core;version="${javax.ws.rs.version.range}",
org.osgi.framework;version="${osgi.framework.import.version.range}",
org.slf4j; version="${slf4j.version.range}",
org.wso2.carbon.kernel;version="${carbon.kernel.package.import.version.range}",
org.wso2.carbon.utils; version="${carbon.utils.version}",
org.wso2.msf4j;version="${msf4j.import.version.range}",
*;resolution:=optional
</import.package>
<carbon.component>
osgi.service; objectClass="org.wso2.msf4j.Microservice"; serviceCount="1"
</carbon.component>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>sonatype.releases</id>
<url>https://oss.sonatype.org/content/repositories/releases/</url>
</repository>
</repositories>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.siddhi.extensions.installer.core.config.mapping;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wso2.carbon.siddhi.extensions.installer.core.exceptions.ExtensionsInstallerException;
import org.wso2.carbon.siddhi.extensions.installer.core.config.mapping.models.ExtensionConfig;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
* Does mapping between the configuration file and Siddhi Extensions Installer.
*/
public class ConfigMapper {

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigMapper.class);

private ConfigMapper() {
// Prevents instantiation.
}

/**
* Maps the given JSON configuration of extensions and their dependencies, to Java Object.
*
* @param configFileLocation Location of the JSON configuration file.
* @return A map that contains extension configurations,
* denoted by extension ids.
* @throws ExtensionsInstallerException Failed to read and map configurations.
*/
public static Map<String, ExtensionConfig> loadAllExtensionConfigs(String configFileLocation)
throws ExtensionsInstallerException {
Gson gson = new Gson();
Type mapType = new TypeToken<Map<String, ExtensionConfig>>() {
}.getType();
try (Reader reader = new InputStreamReader(new FileInputStream(configFileLocation), StandardCharsets.UTF_8)) {
return gson.fromJson(reader, mapType);
} catch (FileNotFoundException e) {
String errorMessage =
String.format("Configuration file not found in: %s.", configFileLocation);
LOGGER.error(errorMessage, e);
throw new ExtensionsInstallerException(errorMessage, e);
} catch (IOException e) {
String errorMessage =
String.format("Unable to read configuration file: %s.", configFileLocation);
LOGGER.error(errorMessage, e);
throw new ExtensionsInstallerException(errorMessage, e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.siddhi.extensions.installer.core.config.mapping.models;

import java.util.Set;

/**
* Contains configuration of a dependency - which will be ultimately a jar file.
*/
public class DependencyConfig {

private String name;
private String version;
private DownloadConfig download;
private String lookupRegex;
private Set<UsageConfig> usages;

public boolean isAutoDownloadable() {
if (download != null) {
return download.isAutoDownloadable();
}
return false;
}

public DownloadConfig getDownload() {
return download;
}

public String getLookupRegex() {
return lookupRegex;
}

public Set<UsageConfig> getUsages() {
return usages;
}

public String getRepresentableName() {
return name + "-" + version;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.siddhi.extensions.installer.core.config.mapping.models;

/**
* Contains a dependency's download configuration.
*/
public class DownloadConfig {

private boolean autoDownloadable;
private String url;

public boolean isAutoDownloadable() {
return autoDownloadable;
}

public String getUrl() {
return url;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.siddhi.extensions.installer.core.config.mapping.models;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* Contains configuration of an extension.
*/
public class ExtensionConfig {

private Map<String, String> extension;
private List<DependencyConfig> dependencies;

public List<DependencyConfig> getManuallyInstallableDependencies() {
if (dependencies != null) {
return dependencies.stream().filter(dependency -> !dependency.isAutoDownloadable())
.collect(Collectors.toList());
}
return Collections.emptyList();
}

public Map<String, String> getExtensionInfo() {
return extension;
}

public List<DependencyConfig> getDependencies() {
return dependencies;
}

}
Loading

0 comments on commit 50fcb48

Please sign in to comment.