This is an automated email from the ASF dual-hosted git repository. zehnder pushed a commit to branch 2133-remove-consul-and-all-related-assets in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 38b67c3aa635265b959a036eb653f29aae4c55be Author: Philipp Zehnder <[email protected]> AuthorDate: Wed Nov 15 08:02:28 2023 +0100 refactor(#2133): Remove consul dependencies from code --- pom.xml | 2 - streampipes-config/pom.xml | 52 ----- .../streampipes/config/backend/BackendConfig.java | 129 ------------ .../config/backend/BackendConfigKeys.java | 44 ---- streampipes-integration-tests/pom.xml | 6 - .../svcdiscovery/AbstractConsulTest.java | 74 ------- .../svcdiscovery/ConsulSpConfigTest.java | 71 ------- .../migrations/v093/ConsulConfigMigration.java | 83 -------- streampipes-service-discovery-consul/pom.xml | 58 ------ .../svcdiscovery/consul/AbstractConsulService.java | 35 ---- .../svcdiscovery/consul/ConsulProvider.java | 106 ---------- .../svcdiscovery/consul/ConsulSpConfig.java | 227 --------------------- streampipes-service-discovery/pom.xml | 5 - .../svcdiscovery/SpServiceDiscovery.java | 17 -- .../service-configs/service-configs.component.ts | 4 +- 15 files changed, 2 insertions(+), 911 deletions(-) diff --git a/pom.xml b/pom.xml index 5fbe3c11f..b26f6c114 100644 --- a/pom.xml +++ b/pom.xml @@ -829,7 +829,6 @@ <module>streampipes-client</module> <module>streampipes-client-api</module> <module>streampipes-commons</module> - <module>streampipes-config</module> <module>streampipes-connect-management</module> <module>streampipes-connect-shared</module> <module>streampipes-extensions-api</module> @@ -871,7 +870,6 @@ <module>streampipes-service-core</module> <module>streampipes-service-core-minimal</module> <module>streampipes-service-discovery</module> - <module>streampipes-service-discovery-consul</module> <module>streampipes-service-discovery-api</module> <module>streampipes-service-extensions</module> <module>streampipes-storage-api</module> diff --git a/streampipes-config/pom.xml b/streampipes-config/pom.xml deleted file mode 100644 index a445066de..000000000 --- a/streampipes-config/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF 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. - ~ - --> - -<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> - <artifactId>streampipes-parent</artifactId> - <groupId>org.apache.streampipes</groupId> - <version>0.95.0-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>streampipes-config</artifactId> - - <dependencies> - <!-- StreamPipes dependencies --> - <dependency> - <groupId>org.apache.streampipes</groupId> - <artifactId>streampipes-model</artifactId> - <version>0.95.0-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.apache.streampipes</groupId> - <artifactId>streampipes-service-discovery</artifactId> - <version>0.95.0-SNAPSHOT</version> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-checkstyle-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/streampipes-config/src/main/java/org/apache/streampipes/config/backend/BackendConfig.java b/streampipes-config/src/main/java/org/apache/streampipes/config/backend/BackendConfig.java deleted file mode 100644 index 7937866ca..000000000 --- a/streampipes-config/src/main/java/org/apache/streampipes/config/backend/BackendConfig.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.apache.streampipes.config.backend; - - -import org.apache.streampipes.commons.environment.Environments; -import org.apache.streampipes.commons.random.TokenGenerator; -import org.apache.streampipes.model.configuration.DefaultMessagingSettings; -import org.apache.streampipes.model.configuration.EmailConfig; -import org.apache.streampipes.model.configuration.GeneralConfig; -import org.apache.streampipes.model.configuration.LocalAuthConfig; -import org.apache.streampipes.model.configuration.MessagingSettings; -import org.apache.streampipes.svcdiscovery.SpServiceDiscovery; -import org.apache.streampipes.svcdiscovery.api.SpConfig; - -public enum BackendConfig { - INSTANCE; - - private final SpConfig config; - - BackendConfig() { - config = SpServiceDiscovery.getSpConfig("backend"); - config.register(BackendConfigKeys.IS_CONFIGURED, false, - "Boolean that indicates whether streampipes is " + "already configured or not"); - } - - public String getJmsHost() { - return config.getString(BackendConfigKeys.JMS_HOST); - } - - public int getJmsPort() { - return config.getInteger(BackendConfigKeys.JMS_PORT); - } - - public String getMqttHost() { - return config.getString(BackendConfigKeys.MQTT_HOST); - } - - public int getMqttPort() { - return config.getInteger(BackendConfigKeys.MQTT_PORT); - } - - public String getNatsHost() { - return config.getString(BackendConfigKeys.NATS_HOST); - } - - public int getNatsPort() { - return config.getInteger(BackendConfigKeys.NATS_PORT); - } - - public String getKafkaHost() { - return config.getString(BackendConfigKeys.KAFKA_HOST); - } - - public int getKafkaPort() { - return config.getInteger(BackendConfigKeys.KAFKA_PORT); - } - - public String getPulsarUrl() { - return config.getString(BackendConfigKeys.PULSAR_URL); - } - - public String getZookeeperHost() { - return config.getString(BackendConfigKeys.ZOOKEEPER_HOST); - } - - public int getZookeeperPort() { - return config.getInteger(BackendConfigKeys.ZOOKEEPER_PORT); - } - - public MessagingSettings getMessagingSettings() { - return config.getObject(BackendConfigKeys.MESSAGING_SETTINGS, MessagingSettings.class, - new DefaultMessagingSettings().make()); - } - - public boolean isConfigured() { - return config.getBoolean(BackendConfigKeys.IS_CONFIGURED); - } - - public void setIsConfigured(boolean b) { - config.setBoolean(BackendConfigKeys.IS_CONFIGURED, b); - } - - public String getAssetDir() { - return config.getString(BackendConfigKeys.ASSETS_DIR); - } - - public String getFilesDir() { - return config.getString(BackendConfigKeys.FILES_DIR); - } - - public LocalAuthConfig getLocalAuthConfig() { - return config.getObject(BackendConfigKeys.LOCAL_AUTH_CONFIG, LocalAuthConfig.class, - LocalAuthConfig.fromDefaults(getJwtSecret())); - } - - public EmailConfig getEmailConfig() { - return config.getObject(BackendConfigKeys.EMAIL_CONFIG, EmailConfig.class, EmailConfig.fromDefaults()); - } - - public GeneralConfig getGeneralConfig() { - return config.getObject(BackendConfigKeys.GENERAL_CONFIG, GeneralConfig.class, new GeneralConfig()); - } - - private String getJwtSecret() { - var env = Environments.getEnvironment(); - return env.getJwtSecret().getValueOrResolve(this::makeDefaultJwtSecret); - } - - private String makeDefaultJwtSecret() { - return TokenGenerator.generateNewToken(); - } -} diff --git a/streampipes-config/src/main/java/org/apache/streampipes/config/backend/BackendConfigKeys.java b/streampipes-config/src/main/java/org/apache/streampipes/config/backend/BackendConfigKeys.java deleted file mode 100644 index b0268f46c..000000000 --- a/streampipes-config/src/main/java/org/apache/streampipes/config/backend/BackendConfigKeys.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.apache.streampipes.config.backend; - -public class BackendConfigKeys { - public static final String BACKEND_HOST = "SP_BACKEND_HOST"; - public static final String BACKEND_PORT = "SP_BACKEND_PORT"; - public static final String JMS_HOST = "SP_JMS_HOST"; - public static final String JMS_PORT = "SP_JMS_PORT"; - public static final String NATS_HOST = "SP_NATS_HOST"; - public static final String NATS_PORT = "SP_NATS_PORT"; - public static final String MQTT_HOST = "SP_MQTT_HOST"; - public static final String MQTT_PORT = "SP_MQTT_PORT"; - public static final String KAFKA_HOST = "SP_KAFKA_HOST"; - public static final String KAFKA_PORT = "SP_KAFKA_PORT"; - public static final String PULSAR_URL = "SP_PULSAR_URL"; - public static final String ZOOKEEPER_HOST = "SP_ZOOKEEPER_HOST"; - public static final String ZOOKEEPER_PORT = "SP_ZOOKEEPER_PORT"; - public static final String IS_CONFIGURED = "SP_IS_CONFIGURED"; - public static final String IS_SETUP_RUNNING = "SP_IS_SETUP_RUNNING"; - public static final String ASSETS_DIR = "SP_ASSETS_DIR"; - public static final String FILES_DIR = "SP_FILES_DIR"; - public static final String MESSAGING_SETTINGS = "SP_MESSAGING_SETTINGS"; - - public static final String LOCAL_AUTH_CONFIG = "SP_LOCAL_AUTH_CONFIG"; - public static final String EMAIL_CONFIG = "SP_EMAIL_CONFIG"; - public static final String GENERAL_CONFIG = "SP_GENERAL_CONFIG"; -} diff --git a/streampipes-integration-tests/pom.xml b/streampipes-integration-tests/pom.xml index aa5465aee..e10fc8621 100644 --- a/streampipes-integration-tests/pom.xml +++ b/streampipes-integration-tests/pom.xml @@ -106,12 +106,6 @@ <version>1.19.0</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.testcontainers</groupId> - <artifactId>consul</artifactId> - <version>1.19.0</version> - <scope>test</scope> - </dependency> <dependency> <groupId>org.testcontainers</groupId> <artifactId>kafka</artifactId> diff --git a/streampipes-integration-tests/src/test/java/org/apache/streampipes/integration/svcdiscovery/AbstractConsulTest.java b/streampipes-integration-tests/src/test/java/org/apache/streampipes/integration/svcdiscovery/AbstractConsulTest.java deleted file mode 100644 index 0e7107f23..000000000 --- a/streampipes-integration-tests/src/test/java/org/apache/streampipes/integration/svcdiscovery/AbstractConsulTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.apache.streampipes.integration.svcdiscovery; - -import org.apache.streampipes.commons.environment.Environment; -import org.apache.streampipes.commons.environment.variable.BooleanEnvironmentVariable; -import org.apache.streampipes.commons.environment.variable.IntEnvironmentVariable; -import org.apache.streampipes.commons.environment.variable.StringEnvironmentVariable; -import org.apache.streampipes.model.extensions.configuration.ConfigItem; - -import org.mockito.Mockito; -import org.testcontainers.consul.ConsulContainer; -import org.testcontainers.utility.DockerImageName; - -import static org.mockito.Mockito.mock; - -public class AbstractConsulTest { - - static final ConsulContainer CONSUL_CONTAINER; - - static { - CONSUL_CONTAINER = new ConsulContainer( - DockerImageName.parse("consul").withTag("1.14.3")) - .withExposedPorts(8500); - CONSUL_CONTAINER.start(); - } - - protected ConfigItem makeConfigItem(String key, String value) { - var item = new ConfigItem(); - item.setKey(key); - item.setValue(value); - item.setPassword(false); - - return item; - } - - protected Environment mockEnvironment() { - var envMock = mock(Environment.class); - var hostVariableMock = mock(StringEnvironmentVariable.class); - var portVariableMock = mock(IntEnvironmentVariable.class); - var consulLocationMock = mock(StringEnvironmentVariable.class); - var spDebugMock = mock(BooleanEnvironmentVariable.class); - - Mockito.when(hostVariableMock.getValueOrDefault()).thenReturn(CONSUL_CONTAINER.getHost()); - Mockito.when(portVariableMock.getValueOrDefault()).thenReturn(CONSUL_CONTAINER.getMappedPort(8500)); - Mockito.when(consulLocationMock.exists()).thenReturn(false); - Mockito.when(spDebugMock.exists()).thenReturn(false); - Mockito.when(spDebugMock.getValueOrReturn(false)).thenReturn(false); - - Mockito.when(envMock.getConsulHost()).thenReturn(hostVariableMock); - Mockito.when(envMock.getConsulPort()).thenReturn(portVariableMock); - Mockito.when(envMock.getConsulLocation()).thenReturn(consulLocationMock); - Mockito.when(envMock.getSpDebug()).thenReturn(spDebugMock); - - return envMock; - - } -} diff --git a/streampipes-integration-tests/src/test/java/org/apache/streampipes/integration/svcdiscovery/ConsulSpConfigTest.java b/streampipes-integration-tests/src/test/java/org/apache/streampipes/integration/svcdiscovery/ConsulSpConfigTest.java deleted file mode 100644 index 7b64d3d39..000000000 --- a/streampipes-integration-tests/src/test/java/org/apache/streampipes/integration/svcdiscovery/ConsulSpConfigTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.apache.streampipes.integration.svcdiscovery; - -import org.apache.streampipes.svcdiscovery.SpServiceDiscovery; -import org.apache.streampipes.svcdiscovery.api.SpConfig; - -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class ConsulSpConfigTest extends AbstractConsulTest { - - private SpConfig spConfig; - @Before - public void before() { - var env = mockEnvironment(); - this.spConfig = SpServiceDiscovery - .getSpConfig("test-service-group", env); - } - - @Test - public void testKvString() { - - spConfig.register("str", "abc", "desc"); - var value = spConfig.getString("str"); - assertEquals("abc", value); - } - - @Test - public void testKvInteger() { - spConfig.register("int", 2, "desc"); - var value = spConfig.getInteger("int"); - assertEquals(2, value); - } - - @Test - public void testKvConfigItem() { - var configItem = makeConfigItem("config", "value"); - spConfig.register(configItem); - var value = spConfig.getConfigItem("config"); - assertEquals(configItem, value); - } - - @Test - public void testUpdateValue() { - spConfig.register("stru", "abc", "desc"); - var value = spConfig.getString("stru"); - assertEquals("abc", value); - spConfig.setString("stru", "abc2"); - var result = spConfig.getString("stru"); - assertEquals("abc2", result); - } -} diff --git a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/v093/ConsulConfigMigration.java b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/v093/ConsulConfigMigration.java deleted file mode 100644 index 53857b12c..000000000 --- a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/v093/ConsulConfigMigration.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.apache.streampipes.service.core.migrations.v093; - -import org.apache.streampipes.config.backend.BackendConfig; -import org.apache.streampipes.config.backend.BackendConfigKeys; -import org.apache.streampipes.model.configuration.DefaultMessagingSettings; -import org.apache.streampipes.model.configuration.SpCoreConfiguration; -import org.apache.streampipes.model.configuration.SpCoreConfigurationStatus; -import org.apache.streampipes.service.core.migrations.Migration; -import org.apache.streampipes.storage.api.ISpCoreConfigurationStorage; -import org.apache.streampipes.storage.management.StorageDispatcher; -import org.apache.streampipes.svcdiscovery.SpServiceDiscovery; - -public class ConsulConfigMigration implements Migration { - - private final ISpCoreConfigurationStorage storage; - - public ConsulConfigMigration() { - this.storage = StorageDispatcher.INSTANCE.getNoSqlStore().getSpCoreConfigurationStorage(); - } - - @Override - public boolean shouldExecute() { - return storage.getAll().isEmpty(); - } - - @Override - public void executeMigration() { - var currConf = BackendConfig.INSTANCE; - var newConf = new SpCoreConfiguration(); - - var pulsarUrlExists = SpServiceDiscovery - .getSpConfig("backend") - .exists(BackendConfigKeys.PULSAR_URL); - - var pulsarUrl = pulsarUrlExists ? currConf.getPulsarUrl() : new DefaultMessagingSettings().make().getPulsarUrl(); - - var messagingSettings = currConf.getMessagingSettings(); - newConf.setLocalAuthConfig(currConf.getLocalAuthConfig()); - newConf.setEmailConfig(currConf.getEmailConfig()); - newConf.setGeneralConfig(currConf.getGeneralConfig()); - - messagingSettings.setJmsHost(currConf.getJmsHost()); - messagingSettings.setJmsPort(currConf.getJmsPort()); - messagingSettings.setMqttHost(currConf.getMqttHost()); - messagingSettings.setMqttPort(currConf.getMqttPort()); - messagingSettings.setNatsHost(currConf.getNatsHost()); - messagingSettings.setNatsPort(currConf.getNatsPort()); - messagingSettings.setKafkaHost(currConf.getKafkaHost()); - messagingSettings.setKafkaPort(currConf.getKafkaPort()); - messagingSettings.setPulsarUrl(pulsarUrl); - messagingSettings.setZookeeperHost(currConf.getZookeeperHost()); - messagingSettings.setZookeeperPort(currConf.getZookeeperPort()); - newConf.setAssetDir(currConf.getAssetDir()); - newConf.setFilesDir(currConf.getFilesDir()); - - newConf.setMessagingSettings(messagingSettings); - newConf.setServiceStatus(SpCoreConfigurationStatus.MIGRATING); - storage.createElement(newConf); - } - - @Override - public String getDescription() { - return "Migrate Consul configurations to CouchDB"; - } -} diff --git a/streampipes-service-discovery-consul/pom.xml b/streampipes-service-discovery-consul/pom.xml deleted file mode 100644 index 4ce579694..000000000 --- a/streampipes-service-discovery-consul/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF 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. - ~ - --> - -<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> - <artifactId>streampipes-parent</artifactId> - <groupId>org.apache.streampipes</groupId> - <version>0.95.0-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>streampipes-service-discovery-consul</artifactId> - - <dependencies> - <dependency> - <groupId>org.apache.streampipes</groupId> - <artifactId>streampipes-serializers-json</artifactId> - <version>0.95.0-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.apache.streampipes</groupId> - <artifactId>streampipes-service-discovery-api</artifactId> - <version>0.95.0-SNAPSHOT</version> - </dependency> - - <!-- third-party dependencies --> - <dependency> - <groupId>com.ecwid.consul</groupId> - <artifactId>consul-api</artifactId> - <version>1.4.5</version> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-checkstyle-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/streampipes-service-discovery-consul/src/main/java/org/apache/streampipes/svcdiscovery/consul/AbstractConsulService.java b/streampipes-service-discovery-consul/src/main/java/org/apache/streampipes/svcdiscovery/consul/AbstractConsulService.java deleted file mode 100644 index d89b387ac..000000000 --- a/streampipes-service-discovery-consul/src/main/java/org/apache/streampipes/svcdiscovery/consul/AbstractConsulService.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.apache.streampipes.svcdiscovery.consul; - -import org.apache.streampipes.commons.environment.Environment; - -import com.ecwid.consul.v1.ConsulClient; - -public abstract class AbstractConsulService { - - private final Environment environment; - - public AbstractConsulService(Environment environment) { - this.environment = environment; - } - - public ConsulClient consulInstance() { - return ConsulProvider.INSTANCE.getConsulInstance(environment); - } -} diff --git a/streampipes-service-discovery-consul/src/main/java/org/apache/streampipes/svcdiscovery/consul/ConsulProvider.java b/streampipes-service-discovery-consul/src/main/java/org/apache/streampipes/svcdiscovery/consul/ConsulProvider.java deleted file mode 100644 index 9148a69ac..000000000 --- a/streampipes-service-discovery-consul/src/main/java/org/apache/streampipes/svcdiscovery/consul/ConsulProvider.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.apache.streampipes.svcdiscovery.consul; - -import org.apache.streampipes.commons.constants.DefaultEnvValues; -import org.apache.streampipes.commons.environment.Environment; - -import com.ecwid.consul.v1.ConsulClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.util.concurrent.TimeUnit; - -public enum ConsulProvider { - - INSTANCE; - - private static final Logger LOG = LoggerFactory.getLogger(ConsulProvider.class); - private static final int CHECK_INTERVAL = 1; - - private ConsulClient consulClient; - private boolean initialized = false; - - ConsulProvider() { - } - - public ConsulClient getConsulInstance(Environment environment) { - if (!initialized) { - createConsulInstance(environment); - } - - return consulClient; - } - - private void createConsulInstance(Environment environment) { - var consulHost = getConsulHost(environment); - var consulPort = getConsulPort(environment); - var connected = false; - - LOG.info("Checking if consul is available on host {} and port {}", consulHost, consulPort); - connected = checkConsulAvailable(consulHost, consulPort); - - if (connected) { - LOG.info("Successfully connected to Consul on host {}", consulHost); - this.consulClient = new ConsulClient(consulHost, consulPort); - this.initialized = true; - } else { - LOG.info("Retrying in {} second", CHECK_INTERVAL); - try { - TimeUnit.SECONDS.sleep(CHECK_INTERVAL); - createConsulInstance(environment); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - - private boolean checkConsulAvailable(String consulHost, - int consulPort) { - try { - InetSocketAddress sa = new InetSocketAddress(consulHost, consulPort); - Socket ss = new Socket(); - ss.connect(sa, 1000); - ss.close(); - - return true; - } catch (IOException e) { - LOG.info("Could not connect to Consul instance..."); - return false; - } - } - - private int getConsulPort(Environment environment) { - return environment.getConsulPort().getValueOrDefault(); - } - - private String getConsulHost(Environment environment) { - if (environment.getConsulLocation().exists()) { - return environment.getConsulLocation().getValue(); - } else { - if (environment.getSpDebug().getValueOrReturn(false)) { - return DefaultEnvValues.LOCALHOST; - } else { - return environment.getConsulHost().getValueOrDefault(); - } - } - } -} diff --git a/streampipes-service-discovery-consul/src/main/java/org/apache/streampipes/svcdiscovery/consul/ConsulSpConfig.java b/streampipes-service-discovery-consul/src/main/java/org/apache/streampipes/svcdiscovery/consul/ConsulSpConfig.java deleted file mode 100644 index 48b3a93ed..000000000 --- a/streampipes-service-discovery-consul/src/main/java/org/apache/streampipes/svcdiscovery/consul/ConsulSpConfig.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.apache.streampipes.svcdiscovery.consul; - -import org.apache.streampipes.commons.environment.Environment; -import org.apache.streampipes.model.extensions.configuration.ConfigItem; -import org.apache.streampipes.model.extensions.configuration.ConfigItemUtils; -import org.apache.streampipes.model.extensions.configuration.ConfigurationScope; -import org.apache.streampipes.serializers.json.JacksonSerializer; -import org.apache.streampipes.svcdiscovery.api.SpConfig; - -import com.ecwid.consul.v1.ConsulClient; -import com.fasterxml.jackson.core.JsonProcessingException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ConsulSpConfig extends AbstractConsulService implements SpConfig { - - public static final String SERVICE_ROUTE_PREFIX = "sp/v1/"; - private static final Logger LOG = LoggerFactory.getLogger(ConsulSpConfig.class); - private static final String SLASH = "/"; - private final String serviceName; - private final ConsulClient kvClient; - - public ConsulSpConfig(String serviceName, - Environment environment) { - super(environment); - this.kvClient = consulInstance(); - this.serviceName = serviceName; - } - - @Override - public <T> void register(String key, T defaultValue, String description, ConfigurationScope configurationScope) { - register(key, String.valueOf(defaultValue), ConfigItemUtils.getValueType(defaultValue), description, - configurationScope, false); - } - - @Override - public void register(String key, boolean defaultValue, String description) { - register(key, Boolean.toString(defaultValue), "xs:boolean", description, - ConfigurationScope.CONTAINER_STARTUP_CONFIG, false); - } - - @Override - public void register(String key, int defaultValue, String description) { - register(key, Integer.toString(defaultValue), "xs:integer", description, - ConfigurationScope.CONTAINER_STARTUP_CONFIG, false); - } - - @Override - public void register(String key, double defaultValue, String description) { - register(key, Double.toString(defaultValue), "xs:double", description, ConfigurationScope.CONTAINER_STARTUP_CONFIG, - false); - - } - - @Override - public void register(String key, String defaultValue, String description) { - register(key, defaultValue, "xs:string", description, ConfigurationScope.CONTAINER_STARTUP_CONFIG, false); - } - - @Override - public void registerObject(String key, Object defaultValue, String description) { - var i = kvClient.getKVValue(addSn(key)); - if (i.getValue() == null) { - kvClient.setKVValue(addSn(key), toJson(defaultValue)); - } - } - - @Override - public void registerPassword(String key, String defaultValue, String description) { - register(key, defaultValue, "xs:string", description, ConfigurationScope.CONTAINER_STARTUP_CONFIG, true); - } - - @Override - public void register(ConfigItem configItem) { - String key = addSn(configItem.getKey()); - var i = kvClient.getKVValue(key); - - if (i.getValue() == null) { - // Set the value of environment variable as default - String envVariable = System.getenv(configItem.getKey()); - if (envVariable != null) { - configItem.setValue(envVariable); - kvClient.setKVValue(key, toJson(configItem)); - } else { - kvClient.setKVValue(key, toJson(configItem)); - } - } - } - - private void register(String key, - String defaultValue, - String valueType, - String description, - ConfigurationScope configurationScope, - boolean isPassword) { - ConfigItem configItem = ConfigItem.from(key, defaultValue, description, valueType, configurationScope, isPassword); - register(configItem); - } - - @Override - public boolean getBoolean(String key) { - return Boolean.parseBoolean(getString(key)); - } - - @Override - public int getInteger(String key) { - return Integer.parseInt(getString(key)); - } - - @Override - public double getDouble(String key) { - return Double.parseDouble(getString(key)); - } - - @Override - public String getString(String key) { - return getConfigItem(key).getValue(); - } - - @Override - public boolean exists(String key) { - var os = kvClient.getKVValue(addSn(key)).getValue(); - return os != null; - } - - @Override - public <T> T getObject(String key, Class<T> clazz, T defaultValue) { - var os = kvClient.getKVValue(addSn(key)); - if (os.getValue() != null) { - try { - return JacksonSerializer.getObjectMapper().readValue(os.getValue().getDecodedValue(), clazz); - } catch (JsonProcessingException e) { - LOG.info("Could not deserialize object", e); - return defaultValue; - } - } else { - return defaultValue; - } - } - - @Override - public ConfigItem getConfigItem(String key) { - var os = kvClient.getKVValue(addSn(key)).getValue(); - return fromJson(os.getDecodedValue()); - } - - @Override - public void setBoolean(String key, Boolean value) { - setString(key, value.toString()); - } - - @Override - public void setInteger(String key, int value) { - setString(key, String.valueOf(value)); - } - - @Override - public void setDouble(String key, double value) { - setString(key, String.valueOf(value)); - } - - @Override - public void setString(String key, String value) { - kvClient.setKVValue(addSn(key), value); - } - - @Override - public void setObject(String key, Object value) { - kvClient.setKVValue(addSn(key), toJson(value)); - } - - private String addSn(String key) { - return SERVICE_ROUTE_PREFIX + serviceName + SLASH + key; - } - - private ConfigItem fromJson(String content) { - try { - return JacksonSerializer.getObjectMapper().readValue(content, ConfigItem.class); - } catch (Exception e) { - // if old config is used, this is a fallback - ConfigItem configItem = new ConfigItem(); - configItem.setValue(content); - return configItem; - } - } - - private ConfigItem prepareConfigItem(String valueType, - String description, - ConfigurationScope configurationScope, - boolean password) { - ConfigItem configItem = new ConfigItem(); - configItem.setValueType(valueType); - configItem.setDescription(description); - configItem.setPassword(password); - configItem.setConfigurationScope(configurationScope); - - return configItem; - } - - private String toJson(Object object) { - try { - return JacksonSerializer.getObjectMapper().writeValueAsString(object); - } catch (JsonProcessingException e) { - LOG.info("Could not serialize object to JSON", e); - return ""; - } - } - -} diff --git a/streampipes-service-discovery/pom.xml b/streampipes-service-discovery/pom.xml index 30be07a50..237ed71d8 100644 --- a/streampipes-service-discovery/pom.xml +++ b/streampipes-service-discovery/pom.xml @@ -38,11 +38,6 @@ <artifactId>streampipes-service-discovery-api</artifactId> <version>0.95.0-SNAPSHOT</version> </dependency> - <dependency> - <groupId>org.apache.streampipes</groupId> - <artifactId>streampipes-service-discovery-consul</artifactId> - <version>0.95.0-SNAPSHOT</version> - </dependency> <dependency> <groupId>org.apache.streampipes</groupId> <artifactId>streampipes-storage-management</artifactId> diff --git a/streampipes-service-discovery/src/main/java/org/apache/streampipes/svcdiscovery/SpServiceDiscovery.java b/streampipes-service-discovery/src/main/java/org/apache/streampipes/svcdiscovery/SpServiceDiscovery.java index e46169a04..ff2d96aa0 100644 --- a/streampipes-service-discovery/src/main/java/org/apache/streampipes/svcdiscovery/SpServiceDiscovery.java +++ b/streampipes-service-discovery/src/main/java/org/apache/streampipes/svcdiscovery/SpServiceDiscovery.java @@ -17,11 +17,7 @@ */ package org.apache.streampipes.svcdiscovery; -import org.apache.streampipes.commons.environment.Environment; -import org.apache.streampipes.commons.environment.Environments; import org.apache.streampipes.svcdiscovery.api.ISpServiceDiscovery; -import org.apache.streampipes.svcdiscovery.api.SpConfig; -import org.apache.streampipes.svcdiscovery.consul.ConsulSpConfig; public class SpServiceDiscovery { @@ -29,17 +25,4 @@ public class SpServiceDiscovery { return new SpServiceDiscoveryCore(); } - public static ISpServiceDiscovery getServiceDiscovery(Environment environment) { - return new SpServiceDiscoveryCore(); - } - - public static SpConfig getSpConfig(String serviceGroup) { - return getSpConfig(serviceGroup, Environments.getEnvironment()); - } - - public static SpConfig getSpConfig(String serviceGroup, - Environment environment) { - return new ConsulSpConfig(serviceGroup, environment); - } - } diff --git a/ui/src/app/configuration/extensions-service-management/extensions-service-configuration/service-configs/service-configs.component.ts b/ui/src/app/configuration/extensions-service-management/extensions-service-configuration/service-configs/service-configs.component.ts index bc1cdb7e6..1f2c75081 100644 --- a/ui/src/app/configuration/extensions-service-management/extensions-service-configuration/service-configs/service-configs.component.ts +++ b/ui/src/app/configuration/extensions-service-management/extensions-service-configuration/service-configs/service-configs.component.ts @@ -26,13 +26,13 @@ import { SpServiceConfiguration } from '@streampipes/platform-services'; providers: [XsService], }) export class ServiceConfigsComponent { - @Input() consulService: SpServiceConfiguration; + @Input() spServiceConfiguration: SpServiceConfiguration; @Output() updateConsulService: EventEmitter<SpServiceConfiguration> = new EventEmitter<SpServiceConfiguration>(); constructor(private service: XsService) {} updateConfiguration(): void { - this.updateConsulService.emit(this.consulService); + this.updateConsulService.emit(this.spServiceConfiguration); } }
