From f16d0a7f9b947493a3ee77fa1f7880a0692a8c54 Mon Sep 17 00:00:00 2001 From: bossenti Date: Sun, 18 Dec 2022 15:29:59 +0100 Subject: [PATCH 1/5] add checkstyle to streampipes-connect-container-master --- streampipes-connect-container-master/pom.xml | 9 +- .../master/health/AdapterHealthCheck.java | 1 + .../master/health/AdapterOperationLock.java | 1 + .../management/AdapterMasterManagement.java | 3 +- .../management/DescriptionManagement.java | 81 ++-- .../master/management/GuessManagement.java | 66 ++-- .../master/management/SourcesManagement.java | 35 +- .../management/UnitMasterManagement.java | 59 +-- .../WorkerAdministrationManagement.java | 3 +- .../master/management/WorkerRestClient.java | 357 +++++++++--------- .../master/management/WorkerUrlProvider.java | 3 +- .../container/master/util/WorkerPaths.java | 2 +- .../master/health/AdapterHealthCheckTest.java | 116 +++--- .../AdapterMasterManagementTest.java | 75 ++-- .../management/DescriptionManagementTest.java | 29 +- .../management/SourcesManagementTest.java | 1 + .../management/UnitMasterManagementTest.java | 172 ++++----- .../management/WorkerRestClientTest.java | 146 +++---- 18 files changed, 599 insertions(+), 560 deletions(-) diff --git a/streampipes-connect-container-master/pom.xml b/streampipes-connect-container-master/pom.xml index 0de492280f..aab185a849 100644 --- a/streampipes-connect-container-master/pom.xml +++ b/streampipes-connect-container-master/pom.xml @@ -17,7 +17,8 @@ ~ --> - + streampipes-parent org.apache.streampipes @@ -97,5 +98,11 @@ streampipes-connect-container-master + + + org.apache.maven.plugins + maven-checkstyle-plugin + + diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheck.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheck.java index 1704c84ce5..689978fde6 100644 --- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheck.java +++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheck.java @@ -13,6 +13,7 @@ * 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.connect.container.master.health; diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterOperationLock.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterOperationLock.java index 38fdd0c5a7..f877e9f938 100644 --- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterOperationLock.java +++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterOperationLock.java @@ -13,6 +13,7 @@ * 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.connect.container.master.health; diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagement.java index c910ce0901..965952f0d2 100644 --- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagement.java +++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagement.java @@ -18,7 +18,6 @@ package org.apache.streampipes.connect.container.master.management; -import org.apache.commons.lang3.RandomStringUtils; import org.apache.streampipes.commons.exceptions.NoServiceEndpointsAvailableException; import org.apache.streampipes.commons.exceptions.SepaParseException; import org.apache.streampipes.connect.adapter.GroundingService; @@ -35,6 +34,8 @@ import org.apache.streampipes.resource.management.SpResourceManager; import org.apache.streampipes.storage.api.IAdapterStorage; import org.apache.streampipes.storage.couchdb.impl.AdapterInstanceStorageImpl; + +import org.apache.commons.lang3.RandomStringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/DescriptionManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/DescriptionManagement.java index da40e49956..38d5fc555b 100644 --- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/DescriptionManagement.java +++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/DescriptionManagement.java @@ -35,55 +35,56 @@ public class DescriptionManagement { - public List getFormats() { - Map allFormats = AdapterRegistry.getAllFormats(); + public List getFormats() { + Map allFormats = AdapterRegistry.getAllFormats(); - List result = new ArrayList<>(); - for (IFormat f : allFormats.values()) { - result.add(f.declareModel()); - } - - return result; + List result = new ArrayList<>(); + for (IFormat f : allFormats.values()) { + result.add(f.declareModel()); } - public List getAdapters() { - IAdapterStorage adapterStorage = CouchDbStorageManager.INSTANCE.getAdapterDescriptionStorage(); - return adapterStorage.getAllAdapters(); - } + return result; + } - public Optional getAdapter(String id) { - return getAdapters().stream() - .filter(desc -> desc.getAppId().equals(id)) - .findFirst(); - } + public List getAdapters() { + IAdapterStorage adapterStorage = CouchDbStorageManager.INSTANCE.getAdapterDescriptionStorage(); + return adapterStorage.getAllAdapters(); + } - public void deleteAdapterDescription(String id) throws SpRuntimeException { - var adapterStorage = CouchDbStorageManager.INSTANCE.getAdapterDescriptionStorage(); - var adapter = adapterStorage.getAdapter(id); - if (!isAdapterUsed(adapter)) { - adapterStorage.deleteAdapter(id); - } else { - throw new SpRuntimeException("This adapter is used by an existing instance and cannot be deleted"); - } - } - public String getAssets(String baseUrl) throws AdapterException { - return WorkerRestClient.getAssets(baseUrl); - } + public Optional getAdapter(String id) { + return getAdapters().stream() + .filter(desc -> desc.getAppId().equals(id)) + .findFirst(); + } - public byte[] getIconAsset(String baseUrl) throws AdapterException { - return WorkerRestClient.getIconAsset(baseUrl); + public void deleteAdapterDescription(String id) throws SpRuntimeException { + var adapterStorage = CouchDbStorageManager.INSTANCE.getAdapterDescriptionStorage(); + var adapter = adapterStorage.getAdapter(id); + if (!isAdapterUsed(adapter)) { + adapterStorage.deleteAdapter(id); + } else { + throw new SpRuntimeException("This adapter is used by an existing instance and cannot be deleted"); } + } - public String getDocumentationAsset(String baseUrl) throws AdapterException { - return WorkerRestClient.getDocumentationAsset(baseUrl); - } + public String getAssets(String baseUrl) throws AdapterException { + return WorkerRestClient.getAssets(baseUrl); + } - private boolean isAdapterUsed(AdapterDescription adapter) { - var allAdapters = StorageDispatcher.INSTANCE.getNoSqlStore().getAdapterInstanceStorage().getAllAdapters(); + public byte[] getIconAsset(String baseUrl) throws AdapterException { + return WorkerRestClient.getIconAsset(baseUrl); + } - return allAdapters - .stream() - .anyMatch(runningAdapter -> runningAdapter.getAppId().equals(adapter.getAppId())); - } + public String getDocumentationAsset(String baseUrl) throws AdapterException { + return WorkerRestClient.getDocumentationAsset(baseUrl); + } + + private boolean isAdapterUsed(AdapterDescription adapter) { + var allAdapters = StorageDispatcher.INSTANCE.getNoSqlStore().getAdapterInstanceStorage().getAllAdapters(); + + return allAdapters + .stream() + .anyMatch(runningAdapter -> runningAdapter.getAppId().equals(adapter.getAppId())); + } } diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/GuessManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/GuessManagement.java index de66c5449a..0caf900c7f 100644 --- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/GuessManagement.java +++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/GuessManagement.java @@ -18,13 +18,6 @@ package org.apache.streampipes.connect.container.master.management; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.client.fluent.Request; -import org.apache.http.client.fluent.Response; -import org.apache.http.entity.ContentType; -import org.apache.http.util.EntityUtils; import org.apache.streampipes.commons.exceptions.NoServiceEndpointsAvailableException; import org.apache.streampipes.commons.exceptions.SpConfigurationException; import org.apache.streampipes.connect.adapter.model.pipeline.AdapterEventPreviewPipeline; @@ -36,6 +29,14 @@ import org.apache.streampipes.model.connect.guess.GuessSchema; import org.apache.streampipes.model.connect.guess.GuessTypeInfo; import org.apache.streampipes.serializers.json.JacksonSerializer; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.fluent.Request; +import org.apache.http.client.fluent.Response; +import org.apache.http.entity.ContentType; +import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,39 +45,40 @@ public class GuessManagement { - private static Logger LOG = LoggerFactory.getLogger(GuessManagement.class); - private WorkerUrlProvider workerUrlProvider; + private static Logger logger = LoggerFactory.getLogger(GuessManagement.class); + private WorkerUrlProvider workerUrlProvider; - public GuessManagement() { - this.workerUrlProvider = new WorkerUrlProvider(); - } + public GuessManagement() { + this.workerUrlProvider = new WorkerUrlProvider(); + } - public GuessSchema guessSchema(AdapterDescription adapterDescription) throws ParseException, WorkerAdapterException, NoServiceEndpointsAvailableException, IOException { - String workerUrl = workerUrlProvider.getWorkerBaseUrl(adapterDescription.getAppId()); + public GuessSchema guessSchema(AdapterDescription adapterDescription) + throws ParseException, WorkerAdapterException, NoServiceEndpointsAvailableException, IOException { + String workerUrl = workerUrlProvider.getWorkerBaseUrl(adapterDescription.getAppId()); - workerUrl = workerUrl + WorkerPaths.getGuessSchemaPath(); + workerUrl = workerUrl + WorkerPaths.getGuessSchemaPath(); - ObjectMapper mapper = JacksonSerializer.getObjectMapper(); - String ad = mapper.writeValueAsString(adapterDescription); - LOG.info("Guess schema at: " + workerUrl); - Response requestResponse = Request.Post(workerUrl) - .bodyString(ad, ContentType.APPLICATION_JSON) - .connectTimeout(1000) - .socketTimeout(100000) - .execute(); + ObjectMapper mapper = JacksonSerializer.getObjectMapper(); + String ad = mapper.writeValueAsString(adapterDescription); + logger.info("Guess schema at: " + workerUrl); + Response requestResponse = Request.Post(workerUrl) + .bodyString(ad, ContentType.APPLICATION_JSON) + .connectTimeout(1000) + .socketTimeout(100000) + .execute(); - HttpResponse httpResponse = requestResponse.returnResponse(); - String responseString = EntityUtils.toString(httpResponse.getEntity()); + HttpResponse httpResponse = requestResponse.returnResponse(); + String responseString = EntityUtils.toString(httpResponse.getEntity()); - if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - return mapper.readValue(responseString, GuessSchema.class); - } else { - var exception = mapper.readValue(responseString, SpConfigurationException.class); - throw new WorkerAdapterException(exception.getMessage(), exception.getCause()); - } + if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + return mapper.readValue(responseString, GuessSchema.class); + } else { + var exception = mapper.readValue(responseString, SpConfigurationException.class); + throw new WorkerAdapterException(exception.getMessage(), exception.getCause()); } + } public Map performAdapterEventPreview(AdapterEventPreview previewRequest) { - return new AdapterEventPreviewPipeline(previewRequest).makePreview(); + return new AdapterEventPreviewPipeline(previewRequest).makePreview(); } } diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/SourcesManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/SourcesManagement.java index 6deb54246b..e2cbd9a716 100644 --- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/SourcesManagement.java +++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/SourcesManagement.java @@ -32,6 +32,7 @@ import org.apache.streampipes.resource.management.secret.SecretProvider; import org.apache.streampipes.sdk.helpers.SupportedProtocols; import org.apache.streampipes.storage.couchdb.impl.AdapterInstanceStorageImpl; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,6 +54,23 @@ public SourcesManagement() { this(new AdapterInstanceStorageImpl()); } + public static SpDataStream updateDataStream(AdapterDescription adapterDescription, + SpDataStream oldDataStream) { + + oldDataStream.setName(adapterDescription.getName()); +// +// // Update event schema + EventSchema newEventSchema; + if (adapterDescription instanceof AdapterStreamDescription) { + newEventSchema = ((AdapterStreamDescription) adapterDescription).getDataStream().getEventSchema(); + } else { + newEventSchema = ((AdapterSetDescription) adapterDescription).getDataSet().getEventSchema(); + } + oldDataStream.setEventSchema(newEventSchema); + + return oldDataStream; + } + public void addSetAdapter(SpDataSet dataSet) throws AdapterException, NoServiceEndpointsAvailableException { AdapterSetDescription ad = (AdapterSetDescription) getAndDecryptAdapter(dataSet.getCorrespondingAdapterId()); @@ -112,23 +130,6 @@ public SpDataStream createAdapterDataStream(AdapterDescription adapterDescriptio return ds; } - public static SpDataStream updateDataStream(AdapterDescription adapterDescription, - SpDataStream oldDataStream) { - - oldDataStream.setName(adapterDescription.getName()); -// -// // Update event schema - EventSchema newEventSchema; - if (adapterDescription instanceof AdapterStreamDescription) { - newEventSchema = ((AdapterStreamDescription) adapterDescription).getDataStream().getEventSchema(); - } else { - newEventSchema = ((AdapterSetDescription) adapterDescription).getDataSet().getEventSchema(); - } - oldDataStream.setEventSchema(newEventSchema); - - return oldDataStream; - } - private AdapterDescription getAndDecryptAdapter(String adapterId) { AdapterDescription adapter = this.adapterInstanceStorage.getAdapter(adapterId); SecretProvider.getDecryptionService().apply(adapter); diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagement.java index 82a0c22659..fd9ff90aae 100644 --- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagement.java +++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagement.java @@ -18,11 +18,12 @@ package org.apache.streampipes.connect.container.master.management; -import com.github.jqudt.Unit; -import com.google.gson.Gson; import org.apache.streampipes.connect.api.exception.AdapterException; import org.apache.streampipes.model.connect.unit.UnitDescription; import org.apache.streampipes.units.UnitProvider; + +import com.github.jqudt.Unit; +import com.google.gson.Gson; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,37 +33,39 @@ public class UnitMasterManagement { - private static final Logger logger = LoggerFactory.getLogger(UnitMasterManagement.class); - private Gson gson; + private static final Logger logger = LoggerFactory.getLogger(UnitMasterManagement.class); + private Gson gson; - public UnitMasterManagement() { - gson = new Gson(); - } - - public String getFittingUnits(UnitDescription unitDescription) throws AdapterException { - List unitDescriptionList = new LinkedList<>(); - Unit unit; + public UnitMasterManagement() { + gson = new Gson(); + } - if(unitDescription.getResource() == null) throw new AdapterException("The resource cannot be null"); - try { - unit = UnitProvider.INSTANCE.getUnit(unitDescription.getResource()); - } catch (IllegalStateException e) { - throw new AdapterException("Invalid URI: " + unitDescription.getResource()); - } - List units = UnitProvider.INSTANCE.getUnitsByType(unit.getType()); + public String getFittingUnits(UnitDescription unitDescription) throws AdapterException { + List unitDescriptionList = new LinkedList<>(); + Unit unit; + if (unitDescription.getResource() == null) { + throw new AdapterException("The resource cannot be null"); + } + try { + unit = UnitProvider.INSTANCE.getUnit(unitDescription.getResource()); + } catch (IllegalStateException e) { + throw new AdapterException("Invalid URI: " + unitDescription.getResource()); + } + List units = UnitProvider.INSTANCE.getUnitsByType(unit.getType()); - for ( Iterator iter = units.iterator(); iter.hasNext(); ) { - Unit unitTmp = (Unit) iter.next(); - try { - UnitDescription unitDescriptionTmp = new UnitDescription(unitTmp.getResource().toString(), unitTmp.getLabel()); - unitDescriptionList.add(unitDescriptionTmp); - } catch (NullPointerException e) { - logger.error("Unit has no resource and/or Label"); - } - } - return gson.toJson(unitDescriptionList); + for (Iterator iter = units.iterator(); iter.hasNext(); ) { + Unit unitTmp = (Unit) iter.next(); + try { + UnitDescription unitDescriptionTmp = new UnitDescription(unitTmp.getResource().toString(), unitTmp.getLabel()); + unitDescriptionList.add(unitDescriptionTmp); + } catch (NullPointerException e) { + logger.error("Unit has no resource and/or Label"); + } } + return gson.toJson(unitDescriptionList); + } + } diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerAdministrationManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerAdministrationManagement.java index 9a5455391f..3b60187760 100644 --- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerAdministrationManagement.java +++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerAdministrationManagement.java @@ -6,13 +6,14 @@ * (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 + * 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.connect.container.master.management; diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerRestClient.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerRestClient.java index 241b93f51d..6503f92f36 100644 --- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerRestClient.java +++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerRestClient.java @@ -18,11 +18,6 @@ package org.apache.streampipes.connect.container.master.management; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.io.IOUtils; -import org.apache.http.HttpResponse; -import org.apache.http.client.fluent.Request; -import org.apache.http.entity.ContentType; import org.apache.streampipes.commons.exceptions.SpConfigurationException; import org.apache.streampipes.connect.api.exception.AdapterException; import org.apache.streampipes.connect.container.master.util.WorkerPaths; @@ -37,6 +32,12 @@ import org.apache.streampipes.storage.api.IAdapterStorage; import org.apache.streampipes.storage.couchdb.impl.AdapterInstanceStorageImpl; import org.apache.streampipes.storage.management.StorageDispatcher; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.fluent.Request; +import org.apache.http.entity.ContentType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,219 +50,221 @@ */ public class WorkerRestClient { - private static final Logger logger = LoggerFactory.getLogger(WorkerRestClient.class); - - public static void invokeStreamAdapter(String endpointUrl, - String elementId) throws AdapterException { - AdapterStreamDescription adapterStreamDescription = (AdapterStreamDescription) getAndDecryptAdapter(elementId); - String url = endpointUrl + WorkerPaths.getStreamInvokePath(); + private static final Logger logger = LoggerFactory.getLogger(WorkerRestClient.class); - startAdapter(url, adapterStreamDescription); - updateStreamAdapterStatus(adapterStreamDescription.getElementId(), true); - } + public static void invokeStreamAdapter(String endpointUrl, + String elementId) throws AdapterException { + AdapterStreamDescription adapterStreamDescription = (AdapterStreamDescription) getAndDecryptAdapter(elementId); + String url = endpointUrl + WorkerPaths.getStreamInvokePath(); - public static void stopStreamAdapter(String baseUrl, - AdapterStreamDescription adapterStreamDescription) throws AdapterException { - String url = baseUrl + WorkerPaths.getStreamStopPath(); + startAdapter(url, adapterStreamDescription); + updateStreamAdapterStatus(adapterStreamDescription.getElementId(), true); + } - AdapterDescription ad = getAdapterDescriptionById(new AdapterInstanceStorageImpl(), adapterStreamDescription.getElementId()); - - stopAdapter(ad, url); - updateStreamAdapterStatus(adapterStreamDescription.getElementId(), false); - } + public static void stopStreamAdapter(String baseUrl, + AdapterStreamDescription adapterStreamDescription) throws AdapterException { + String url = baseUrl + WorkerPaths.getStreamStopPath(); - public static void invokeSetAdapter(String endpointUrl, - AdapterSetDescription adapterSetDescription) throws AdapterException { - String url = endpointUrl + WorkerPaths.getSetInvokePath(); + AdapterDescription ad = + getAdapterDescriptionById(new AdapterInstanceStorageImpl(), adapterStreamDescription.getElementId()); - startAdapter(url, adapterSetDescription); - } + stopAdapter(ad, url); + updateStreamAdapterStatus(adapterStreamDescription.getElementId(), false); + } - public static void stopSetAdapter(String baseUrl, + public static void invokeSetAdapter(String endpointUrl, AdapterSetDescription adapterSetDescription) throws AdapterException { - String url = baseUrl + WorkerPaths.getSetStopPath(); + String url = endpointUrl + WorkerPaths.getSetInvokePath(); - stopAdapter(adapterSetDescription, url); - } + startAdapter(url, adapterSetDescription); + } - public static List getAllRunningAdapterInstanceDescriptions(String url) throws AdapterException { - try { - logger.info("Requesting all running adapter description instances: " + url); + public static void stopSetAdapter(String baseUrl, + AdapterSetDescription adapterSetDescription) throws AdapterException { + String url = baseUrl + WorkerPaths.getSetStopPath(); - String responseString = Request.Get(url) - .connectTimeout(1000) - .socketTimeout(100000) - .execute().returnContent().asString(); + stopAdapter(adapterSetDescription, url); + } - List result = JacksonSerializer.getObjectMapper().readValue(responseString, List.class); + public static List getAllRunningAdapterInstanceDescriptions(String url) throws AdapterException { + try { + logger.info("Requesting all running adapter description instances: " + url); - return result; - } catch (IOException e) { - logger.error("List of running adapters could not be fetched", e); - throw new AdapterException("List of running adapters could not be fetched from: " + url); - } - } + String responseString = Request.Get(url) + .connectTimeout(1000) + .socketTimeout(100000) + .execute().returnContent().asString(); - public static void startAdapter(String url, - AdapterDescription ad) throws AdapterException { - logger.info("Trying to start adapter on endpoint {} ", url); - triggerAdapterStateChange(ad, url, "started"); + List result = JacksonSerializer.getObjectMapper().readValue(responseString, List.class); + + return result; + } catch (IOException e) { + logger.error("List of running adapters could not be fetched", e); + throw new AdapterException("List of running adapters could not be fetched from: " + url); } + } + public static void startAdapter(String url, + AdapterDescription ad) throws AdapterException { + logger.info("Trying to start adapter on endpoint {} ", url); + triggerAdapterStateChange(ad, url, "started"); + } - public static void stopAdapter(AdapterDescription ad, - String url) throws AdapterException { - logger.info("Trying to stop adapter on endpoint {} ", url); - triggerAdapterStateChange(ad, url, "stopped"); - } + public static void stopAdapter(AdapterDescription ad, + String url) throws AdapterException { - private static void triggerAdapterStateChange(AdapterDescription ad, - String url, - String action) throws AdapterException { - try { - String adapterDescription = JacksonSerializer.getObjectMapper().writeValueAsString(ad); + logger.info("Trying to stop adapter on endpoint {} ", url); + triggerAdapterStateChange(ad, url, "stopped"); + } - var response = triggerPost(url, adapterDescription); - var responseString = getResponseBody(response); + private static void triggerAdapterStateChange(AdapterDescription ad, + String url, + String action) throws AdapterException { + try { + String adapterDescription = JacksonSerializer.getObjectMapper().writeValueAsString(ad); - if (response.getStatusLine().getStatusCode() != 200) { - var exception = getSerializer().readValue(responseString, AdapterException.class); - throw new AdapterException(exception.getMessage(), exception.getCause()); - } + var response = triggerPost(url, adapterDescription); + var responseString = getResponseBody(response); - logger.info("Adapter {} on endpoint: " + url + " with Response: " + responseString); + if (response.getStatusLine().getStatusCode() != 200) { + var exception = getSerializer().readValue(responseString, AdapterException.class); + throw new AdapterException(exception.getMessage(), exception.getCause()); + } - } catch (IOException e) { - logger.error("Adapter was not {} successfully", action, e); - throw new AdapterException("Adapter was not " + action + " successfully with url " + url, e); - } - } + logger.info("Adapter {} on endpoint: " + url + " with Response: " + responseString); - private static String getResponseBody(HttpResponse response) throws IOException { - return IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); + } catch (IOException e) { + logger.error("Adapter was not {} successfully", action, e); + throw new AdapterException("Adapter was not " + action + " successfully with url " + url, e); } - - private static HttpResponse triggerPost(String url, - String payload) throws IOException { - return Request.Post(url) + } + + private static String getResponseBody(HttpResponse response) throws IOException { + return IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); + } + + private static HttpResponse triggerPost(String url, + String payload) throws IOException { + return Request.Post(url) + .bodyString(payload, ContentType.APPLICATION_JSON) + .connectTimeout(1000) + .socketTimeout(100000) + .execute().returnResponse(); + } + + public static RuntimeOptionsResponse getConfiguration(String workerEndpoint, + String appId, + RuntimeOptionsRequest runtimeOptionsRequest) + throws AdapterException, SpConfigurationException { + String url = workerEndpoint + WorkerPaths.getRuntimeResolvablePath(appId); + + try { + String payload = JacksonSerializer.getObjectMapper().writeValueAsString(runtimeOptionsRequest); + var response = Request.Post(url) .bodyString(payload, ContentType.APPLICATION_JSON) .connectTimeout(1000) .socketTimeout(100000) - .execute().returnResponse(); - } - - public static RuntimeOptionsResponse getConfiguration(String workerEndpoint, - String appId, - RuntimeOptionsRequest runtimeOptionsRequest) throws AdapterException, SpConfigurationException { - String url = workerEndpoint + WorkerPaths.getRuntimeResolvablePath(appId); - - try { - String payload = JacksonSerializer.getObjectMapper().writeValueAsString(runtimeOptionsRequest); - var response = Request.Post(url) - .bodyString(payload, ContentType.APPLICATION_JSON) - .connectTimeout(1000) - .socketTimeout(100000) - .execute() - .returnResponse(); - - String responseString = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); - - if (response.getStatusLine().getStatusCode() == 200) { - return getSerializer().readValue(responseString, RuntimeOptionsResponse.class); - } else { - var exception = getSerializer().readValue(responseString, SpConfigurationException.class); - throw new SpConfigurationException(exception.getMessage(), exception.getCause()); - } - } catch (IOException e) { - e.printStackTrace(); - throw new AdapterException("Could not resolve runtime configurations from " + url); - } - } - - public static String getAssets(String workerPath) throws AdapterException { - String url = workerPath + "/assets"; - logger.info("Trying to Assets from endpoint: " + url); - - try { - return Request.Get(url) - .connectTimeout(1000) - .socketTimeout(100000) - .execute().returnContent().asString(); - } catch (IOException e) { - logger.error(e.getMessage()); - throw new AdapterException("Could not get assets endpoint: " + url); - } - + .execute() + .returnResponse(); + + String responseString = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); + + if (response.getStatusLine().getStatusCode() == 200) { + return getSerializer().readValue(responseString, RuntimeOptionsResponse.class); + } else { + var exception = getSerializer().readValue(responseString, SpConfigurationException.class); + throw new SpConfigurationException(exception.getMessage(), exception.getCause()); + } + } catch (IOException e) { + e.printStackTrace(); + throw new AdapterException("Could not resolve runtime configurations from " + url); } + } - public static byte[] getIconAsset(String baseUrl) throws AdapterException { - String url = baseUrl + "/assets/icon"; - - try { - byte[] responseString = Request.Get(url) - .connectTimeout(1000) - .socketTimeout(100000) - .execute().returnContent().asBytes(); - return responseString; - } catch (IOException e) { - logger.error(e.getMessage()); - throw new AdapterException("Could not get icon endpoint: " + url); - } - } + public static String getAssets(String workerPath) throws AdapterException { + String url = workerPath + "/assets"; + logger.info("Trying to Assets from endpoint: " + url); - public static String getDocumentationAsset(String baseUrl) throws AdapterException { - String url = baseUrl + "/assets/documentation"; - - try { - return Request.Get(url) - .connectTimeout(1000) - .socketTimeout(100000) - .execute().returnContent().asString(); - } catch (IOException e) { - logger.error(e.getMessage()); - throw new AdapterException("Could not get documentation endpoint: " + url); - } + try { + return Request.Get(url) + .connectTimeout(1000) + .socketTimeout(100000) + .execute().returnContent().asString(); + } catch (IOException e) { + logger.error(e.getMessage()); + throw new AdapterException("Could not get assets endpoint: " + url); } + } - private static AdapterDescription getAdapterDescriptionById(AdapterInstanceStorageImpl adapterStorage, String id) { - AdapterDescription adapterDescription = null; - List allAdapters = adapterStorage.getAllAdapters(); - for (AdapterDescription a : allAdapters) { - if (a.getElementId().endsWith(id)) { - adapterDescription = a; - } - } + public static byte[] getIconAsset(String baseUrl) throws AdapterException { + String url = baseUrl + "/assets/icon"; - return adapterDescription; + try { + byte[] responseString = Request.Get(url) + .connectTimeout(1000) + .socketTimeout(100000) + .execute().returnContent().asBytes(); + return responseString; + } catch (IOException e) { + logger.error(e.getMessage()); + throw new AdapterException("Could not get icon endpoint: " + url); } + } - private static void updateStreamAdapterStatus(String adapterId, - boolean running) { - AdapterStreamDescription adapter = (AdapterStreamDescription) getAndDecryptAdapter(adapterId); - adapter.setRunning(running); - encryptAndUpdateAdapter(adapter); - } + public static String getDocumentationAsset(String baseUrl) throws AdapterException { + String url = baseUrl + "/assets/documentation"; - private static void encryptAndUpdateAdapter(AdapterDescription adapter) { - AdapterDescription encryptedDescription = new Cloner().adapterDescription(adapter); - SecretProvider.getEncryptionService().apply(encryptedDescription); - getAdapterStorage().updateAdapter(encryptedDescription); + try { + return Request.Get(url) + .connectTimeout(1000) + .socketTimeout(100000) + .execute().returnContent().asString(); + } catch (IOException e) { + logger.error(e.getMessage()); + throw new AdapterException("Could not get documentation endpoint: " + url); } + } - private static AdapterDescription getAndDecryptAdapter(String adapterId) { - AdapterDescription adapter = getAdapterStorage().getAdapter(adapterId); - SecretProvider.getDecryptionService().apply(adapter); - return adapter; - } - private static IAdapterStorage getAdapterStorage() { - return StorageDispatcher.INSTANCE.getNoSqlStore().getAdapterInstanceStorage(); + private static AdapterDescription getAdapterDescriptionById(AdapterInstanceStorageImpl adapterStorage, String id) { + AdapterDescription adapterDescription = null; + List allAdapters = adapterStorage.getAllAdapters(); + for (AdapterDescription a : allAdapters) { + if (a.getElementId().endsWith(id)) { + adapterDescription = a; + } } - private static ObjectMapper getSerializer() { - return JacksonSerializer.getObjectMapper(); - } + return adapterDescription; + } + + private static void updateStreamAdapterStatus(String adapterId, + boolean running) { + AdapterStreamDescription adapter = (AdapterStreamDescription) getAndDecryptAdapter(adapterId); + adapter.setRunning(running); + encryptAndUpdateAdapter(adapter); + } + + private static void encryptAndUpdateAdapter(AdapterDescription adapter) { + AdapterDescription encryptedDescription = new Cloner().adapterDescription(adapter); + SecretProvider.getEncryptionService().apply(encryptedDescription); + getAdapterStorage().updateAdapter(encryptedDescription); + } + + private static AdapterDescription getAndDecryptAdapter(String adapterId) { + AdapterDescription adapter = getAdapterStorage().getAdapter(adapterId); + SecretProvider.getDecryptionService().apply(adapter); + return adapter; + } + + private static IAdapterStorage getAdapterStorage() { + return StorageDispatcher.INSTANCE.getNoSqlStore().getAdapterInstanceStorage(); + } + + private static ObjectMapper getSerializer() { + return JacksonSerializer.getObjectMapper(); + } } diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerUrlProvider.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerUrlProvider.java index 56868784eb..7968e93793 100644 --- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerUrlProvider.java +++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerUrlProvider.java @@ -24,7 +24,8 @@ public class WorkerUrlProvider { - public WorkerUrlProvider() {} + public WorkerUrlProvider() { + } public String getWorkerUrl(String appId) throws NoServiceEndpointsAvailableException { return getEndpointGenerator(appId).getEndpointResourceUrl(); diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/util/WorkerPaths.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/util/WorkerPaths.java index 1a48828931..b7dab10329 100644 --- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/util/WorkerPaths.java +++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/util/WorkerPaths.java @@ -37,7 +37,7 @@ public static String getStreamStopPath() { } public static String getSetInvokePath() { - return WorkerMainPath + "/set/invoke"; + return WorkerMainPath + "/set/invoke"; } public static String getSetStopPath() { diff --git a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheckTest.java b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheckTest.java index a74de380c2..12b7eb3038 100644 --- a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheckTest.java +++ b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheckTest.java @@ -24,6 +24,7 @@ import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription; import org.apache.streampipes.sdk.builder.adapter.SpecificDataStreamAdapterBuilder; import org.apache.streampipes.storage.couchdb.impl.AdapterInstanceStorageImpl; + import org.junit.Test; import java.util.HashMap; @@ -40,81 +41,82 @@ public class AdapterHealthCheckTest { - private final String testElementId = "testElementId"; + private final String testElementId = "testElementId"; - @Test - public void getAllRunningInstancesAdapterDescriptions() { - AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class); - when(adapterStorage.getAllAdapters()).thenReturn(getAdapterDescriptionList()); + @Test + public void getAllRunningInstancesAdapterDescriptions() { + AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class); + when(adapterStorage.getAllAdapters()).thenReturn(getAdapterDescriptionList()); - AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(adapterStorage, null); - Map result = adapterHealthCheck.getAllRunningInstancesAdapterDescriptions(); + AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(adapterStorage, null); + Map result = adapterHealthCheck.getAllRunningInstancesAdapterDescriptions(); - assertNotNull(result); - assertEquals(1, result.keySet().size()); - assertEquals(getAdapterDescriptionList().get(0), result.get(testElementId)); - } + assertNotNull(result); + assertEquals(1, result.keySet().size()); + assertEquals(getAdapterDescriptionList().get(0), result.get(testElementId)); + } - @Test - public void getAllWorkersWithAdapters() { - AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class); - when(adapterStorage.getAllAdapters()).thenReturn(getAdapterDescriptionList()); + @Test + public void getAllWorkersWithAdapters() { + AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class); + when(adapterStorage.getAllAdapters()).thenReturn(getAdapterDescriptionList()); - AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(null, null); - Map> result = adapterHealthCheck.getAllWorkersWithAdapters(getAdapterDescriptionMap()); + AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(null, null); + Map> result = + adapterHealthCheck.getAllWorkersWithAdapters(getAdapterDescriptionMap()); - assertNotNull(result); - assertEquals(1, result.keySet().size()); - String selectedEndpointUrl = "http://test.de"; - assertEquals(1, result.get(selectedEndpointUrl).size()); - assertEquals(getAdapterDescriptionList().get(0), result.get(selectedEndpointUrl).get(0)); - } + assertNotNull(result); + assertEquals(1, result.keySet().size()); + String selectedEndpointUrl = "http://test.de"; + assertEquals(1, result.get(selectedEndpointUrl).size()); + assertEquals(getAdapterDescriptionList().get(0), result.get(selectedEndpointUrl).get(0)); + } - @Test - public void recoverRunningAdaptersTest() throws AdapterException { - AdapterMasterManagement adapterMasterManagementMock = mock(AdapterMasterManagement.class); - AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(null, adapterMasterManagementMock); + @Test + public void recoverRunningAdaptersTest() throws AdapterException { + AdapterMasterManagement adapterMasterManagementMock = mock(AdapterMasterManagement.class); + AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(null, adapterMasterManagementMock); - adapterHealthCheck.recoverAdapters(getAdaptersToRecoverData(true)); + adapterHealthCheck.recoverAdapters(getAdaptersToRecoverData(true)); - verify(adapterMasterManagementMock, times(1)).startStreamAdapter(any()); - } + verify(adapterMasterManagementMock, times(1)).startStreamAdapter(any()); + } - @Test - public void recoverStoppedAdaptersTest() throws AdapterException { - AdapterMasterManagement adapterMasterManagementMock = mock(AdapterMasterManagement.class); - AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(null, adapterMasterManagementMock); + @Test + public void recoverStoppedAdaptersTest() throws AdapterException { + AdapterMasterManagement adapterMasterManagementMock = mock(AdapterMasterManagement.class); + AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(null, adapterMasterManagementMock); - adapterHealthCheck.recoverAdapters(getAdaptersToRecoverData(false)); + adapterHealthCheck.recoverAdapters(getAdaptersToRecoverData(false)); - verify(adapterMasterManagementMock, times(0)).startStreamAdapter(any()); - } + verify(adapterMasterManagementMock, times(0)).startStreamAdapter(any()); + } - private Map getAdaptersToRecoverData(boolean isRunning) { - Map adaptersToRecover = new HashMap<>(); - AdapterStreamDescription ad = SpecificDataStreamAdapterBuilder.create("").build(); - ad.setRunning(isRunning); - adaptersToRecover.put("", ad); - return adaptersToRecover; - } + private Map getAdaptersToRecoverData(boolean isRunning) { + Map adaptersToRecover = new HashMap<>(); + AdapterStreamDescription ad = SpecificDataStreamAdapterBuilder.create("").build(); + ad.setRunning(isRunning); + adaptersToRecover.put("", ad); + return adaptersToRecover; + } - private List getAdapterDescriptionList() { + private List getAdapterDescriptionList() { - SpecificAdapterStreamDescription adapterStreamDescription = SpecificDataStreamAdapterBuilder - .create("testAppId", "Test Adapter", "") - .elementId(testElementId) - .build(); - adapterStreamDescription.setSelectedEndpointUrl("http://test.de"); + SpecificAdapterStreamDescription adapterStreamDescription = SpecificDataStreamAdapterBuilder + .create("testAppId", "Test Adapter", "") + .elementId(testElementId) + .build(); + adapterStreamDescription.setSelectedEndpointUrl("http://test.de"); - return List.of(adapterStreamDescription); - } + return List.of(adapterStreamDescription); + } - private Map getAdapterDescriptionMap() { - Map result = new HashMap<>(); - result.put(testElementId, getAdapterDescriptionList().get(0)); + private Map getAdapterDescriptionMap() { + Map result = new HashMap<>(); + result.put(testElementId, getAdapterDescriptionList().get(0)); - return result; - } + return result; + } } \ No newline at end of file diff --git a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagementTest.java b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagementTest.java index 00826a6875..108988e36e 100644 --- a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagementTest.java +++ b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagementTest.java @@ -23,6 +23,7 @@ import org.apache.streampipes.model.connect.adapter.GenericAdapterStreamDescription; import org.apache.streampipes.resource.management.AdapterResourceManager; import org.apache.streampipes.storage.couchdb.impl.AdapterInstanceStorageImpl; + import org.junit.Test; import java.util.Arrays; @@ -34,52 +35,56 @@ public class AdapterMasterManagementTest { - @Test(expected = AdapterException.class) - public void getAdapterFailNull() throws AdapterException { - AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class); - AdapterResourceManager resourceManager = mock(AdapterResourceManager.class); - when(adapterStorage.getAllAdapters()).thenReturn(null); + @Test(expected = AdapterException.class) + public void getAdapterFailNull() throws AdapterException { + AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class); + AdapterResourceManager resourceManager = mock(AdapterResourceManager.class); + when(adapterStorage.getAllAdapters()).thenReturn(null); - AdapterMasterManagement adapterMasterManagement = new AdapterMasterManagement(adapterStorage, resourceManager, null); + AdapterMasterManagement adapterMasterManagement = + new AdapterMasterManagement(adapterStorage, resourceManager, null); - adapterMasterManagement.getAdapter("id2"); - } + adapterMasterManagement.getAdapter("id2"); + } - @Test(expected = AdapterException.class) - public void getAdapterFail() throws AdapterException { - List adapterDescriptions = Arrays.asList(new GenericAdapterStreamDescription()); - AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class); - AdapterResourceManager resourceManager = mock(AdapterResourceManager.class); - when(adapterStorage.getAllAdapters()).thenReturn(adapterDescriptions); + @Test(expected = AdapterException.class) + public void getAdapterFail() throws AdapterException { + List adapterDescriptions = Arrays.asList(new GenericAdapterStreamDescription()); + AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class); + AdapterResourceManager resourceManager = mock(AdapterResourceManager.class); + when(adapterStorage.getAllAdapters()).thenReturn(adapterDescriptions); - AdapterMasterManagement adapterMasterManagement = new AdapterMasterManagement(adapterStorage, resourceManager, null); + AdapterMasterManagement adapterMasterManagement = + new AdapterMasterManagement(adapterStorage, resourceManager, null); - adapterMasterManagement.getAdapter("id2"); - } + adapterMasterManagement.getAdapter("id2"); + } - @Test - public void getAllAdaptersSuccess() throws AdapterException { - List adapterDescriptions = Arrays.asList(new GenericAdapterStreamDescription()); - AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class); - AdapterResourceManager resourceManager = mock(AdapterResourceManager.class); - when(adapterStorage.getAllAdapters()).thenReturn(adapterDescriptions); + @Test + public void getAllAdaptersSuccess() throws AdapterException { + List adapterDescriptions = Arrays.asList(new GenericAdapterStreamDescription()); + AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class); + AdapterResourceManager resourceManager = mock(AdapterResourceManager.class); + when(adapterStorage.getAllAdapters()).thenReturn(adapterDescriptions); - AdapterMasterManagement adapterMasterManagement = new AdapterMasterManagement(adapterStorage, resourceManager, null); + AdapterMasterManagement adapterMasterManagement = + new AdapterMasterManagement(adapterStorage, resourceManager, null); - List result = adapterMasterManagement.getAllAdapterInstances(); + List result = adapterMasterManagement.getAllAdapterInstances(); - assertEquals(1, result.size()); - } + assertEquals(1, result.size()); + } - @Test(expected = AdapterException.class) - public void getAllAdaptersFail() throws AdapterException { - AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class); - AdapterResourceManager resourceManager = mock(AdapterResourceManager.class); - when(adapterStorage.getAllAdapters()).thenReturn(null); + @Test(expected = AdapterException.class) + public void getAllAdaptersFail() throws AdapterException { + AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class); + AdapterResourceManager resourceManager = mock(AdapterResourceManager.class); + when(adapterStorage.getAllAdapters()).thenReturn(null); - AdapterMasterManagement adapterMasterManagement = new AdapterMasterManagement(adapterStorage, resourceManager, null); + AdapterMasterManagement adapterMasterManagement = + new AdapterMasterManagement(adapterStorage, resourceManager, null); - adapterMasterManagement.getAllAdapterInstances(); + adapterMasterManagement.getAllAdapterInstances(); - } + } } diff --git a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/DescriptionManagementTest.java b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/DescriptionManagementTest.java index 4a470fbd8c..bd4ca43c5d 100644 --- a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/DescriptionManagementTest.java +++ b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/DescriptionManagementTest.java @@ -22,6 +22,7 @@ import org.apache.streampipes.connect.adapter.format.json.arraykey.JsonFormat; import org.apache.streampipes.connect.api.IFormat; import org.apache.streampipes.model.connect.grounding.FormatDescription; + import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @@ -38,27 +39,27 @@ import static org.junit.Assert.assertNotNull; @RunWith(PowerMockRunner.class) -@PrepareForTest({ AdapterRegistry.class }) +@PrepareForTest({AdapterRegistry.class}) @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) public class DescriptionManagementTest { - @Test - public void getFormats() { - Map allFormats = new HashMap<>(); - allFormats.put(JsonFormat.ID, new JsonFormat()); + @Test + public void getFormats() { + Map allFormats = new HashMap<>(); + allFormats.put(JsonFormat.ID, new JsonFormat()); - PowerMockito.mockStatic(AdapterRegistry.class); - Mockito.when(AdapterRegistry.getAllFormats()) - .thenReturn(allFormats); + PowerMockito.mockStatic(AdapterRegistry.class); + Mockito.when(AdapterRegistry.getAllFormats()) + .thenReturn(allFormats); - DescriptionManagement descriptionManagement = new DescriptionManagement(); + DescriptionManagement descriptionManagement = new DescriptionManagement(); - List result = descriptionManagement.getFormats(); + List result = descriptionManagement.getFormats(); - assertNotNull(result); - assertEquals(1, result.size()); - assertEquals(JsonFormat.ID, result.get(0).getAppId()); - } + assertNotNull(result); + assertEquals(1, result.size()); + assertEquals(JsonFormat.ID, result.get(0).getAppId()); + } } diff --git a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/SourcesManagementTest.java b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/SourcesManagementTest.java index e355aa937a..537f4db131 100644 --- a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/SourcesManagementTest.java +++ b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/SourcesManagementTest.java @@ -23,6 +23,7 @@ import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription; import org.apache.streampipes.model.schema.EventPropertyPrimitive; import org.apache.streampipes.model.schema.EventSchema; + import org.junit.Before; import org.junit.Test; diff --git a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagementTest.java b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagementTest.java index 0c8f8bb877..2983be12a3 100644 --- a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagementTest.java +++ b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagementTest.java @@ -18,11 +18,9 @@ package org.apache.streampipes.connect.container.master.management; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; +import org.apache.streampipes.connect.api.exception.AdapterException; +import org.apache.streampipes.model.connect.unit.UnitDescription; +import org.apache.streampipes.units.UnitProvider; import com.github.jqudt.Unit; import com.github.jqudt.onto.UnitFactory; @@ -33,94 +31,98 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; -import org.apache.streampipes.connect.api.exception.AdapterException; -import org.apache.streampipes.model.connect.unit.UnitDescription; -import org.apache.streampipes.units.UnitProvider; import java.net.URI; import java.util.ArrayList; import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.when; + @RunWith(PowerMockRunner.class) -@PrepareForTest({ UnitProvider.class, UnitFactory.class }) +@PrepareForTest({UnitProvider.class, UnitFactory.class}) @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) public class UnitMasterManagementTest { - @Test(expected = AdapterException.class) - public void URLisNull() throws AdapterException { - UnitMasterManagement unitMasterManagement = new UnitMasterManagement(); - unitMasterManagement.getFittingUnits(getUnitDescription("",null)); - } - - @Test(expected = AdapterException.class) - @Ignore - public void invalidURL() throws AdapterException { - UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass()); - when(unitProvider.getUnit(anyString())).thenThrow(new IllegalStateException()); - - UnitMasterManagement unitMasterManagement = new UnitMasterManagement(); - unitMasterManagement.getFittingUnits(getUnitDescription("","http://test")); - } - - @Test - public void getFittingUnitsEmpty() throws Exception { - UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass()); - when(unitProvider.getUnit(anyString())).thenReturn(new Unit()); - when(unitProvider.getUnitsByType(any())).thenReturn((new ArrayList<>())); - Whitebox.setInternalState(UnitProvider.class, "INSTANCE", unitProvider); - - UnitMasterManagement unitMasterManagement = new UnitMasterManagement(); - String jsonResult = unitMasterManagement.getFittingUnits(getUnitDescription("","")); - assertEquals("[]", jsonResult); - } - - @Test - public void getFittingUnitsUnitsEmpty() throws Exception { - UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass()); - when(unitProvider.getUnit(anyString())).thenReturn(new Unit()); - - List unitList = new ArrayList<>(2); - unitList.add(new Unit()); - unitList.add(new Unit()); - - when(unitProvider.getUnitsByType(any())).thenReturn((unitList)); - Whitebox.setInternalState(UnitProvider.class, "INSTANCE", unitProvider); - - UnitMasterManagement unitMasterManagement = new UnitMasterManagement(); - String jsonResult = unitMasterManagement.getFittingUnits(getUnitDescription("","")); - assertEquals("[]", jsonResult); - } - - @Test - public void getFittingUnitsUnits() throws Exception { - UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass()); - when(unitProvider.getUnit(anyString())).thenReturn(new Unit()); - - List unitList = new ArrayList<>(2); - Unit unit = new Unit(); - unit.setLabel("A"); - unit.setResource(new URI("http://A")); - unitList.add(unit); - unit = new Unit(); - unit.setLabel("A"); - unit.setResource(new URI("http://A")); - unitList.add(unit); - unitList.add(new Unit()); - - when(unitProvider.getUnitsByType(any())).thenReturn((unitList)); - Whitebox.setInternalState(UnitProvider.class, "INSTANCE", unitProvider); - - UnitMasterManagement unitMasterManagement = new UnitMasterManagement(); - String jsonResult = unitMasterManagement.getFittingUnits(getUnitDescription("","")); - assertEquals("[{\"resource\":\"http://A\",\"label\":\"A\"},{\"resource\":\"http://A\",\"label\":\"A\"}]", jsonResult); - } - - - private UnitDescription getUnitDescription(String label, String ressource) { - UnitDescription unitDescription = new UnitDescription(); - unitDescription.setLabel(label); - unitDescription.setResource(ressource); - return unitDescription; - } + @Test(expected = AdapterException.class) + public void URLisNull() throws AdapterException { + UnitMasterManagement unitMasterManagement = new UnitMasterManagement(); + unitMasterManagement.getFittingUnits(getUnitDescription("", null)); + } + + @Test(expected = AdapterException.class) + @Ignore + public void invalidURL() throws AdapterException { + UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass()); + when(unitProvider.getUnit(anyString())).thenThrow(new IllegalStateException()); + + UnitMasterManagement unitMasterManagement = new UnitMasterManagement(); + unitMasterManagement.getFittingUnits(getUnitDescription("", "http://test")); + } + + @Test + public void getFittingUnitsEmpty() throws Exception { + UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass()); + when(unitProvider.getUnit(anyString())).thenReturn(new Unit()); + when(unitProvider.getUnitsByType(any())).thenReturn((new ArrayList<>())); + Whitebox.setInternalState(UnitProvider.class, "INSTANCE", unitProvider); + + UnitMasterManagement unitMasterManagement = new UnitMasterManagement(); + String jsonResult = unitMasterManagement.getFittingUnits(getUnitDescription("", "")); + assertEquals("[]", jsonResult); + } + + @Test + public void getFittingUnitsUnitsEmpty() throws Exception { + UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass()); + when(unitProvider.getUnit(anyString())).thenReturn(new Unit()); + + List unitList = new ArrayList<>(2); + unitList.add(new Unit()); + unitList.add(new Unit()); + + when(unitProvider.getUnitsByType(any())).thenReturn((unitList)); + Whitebox.setInternalState(UnitProvider.class, "INSTANCE", unitProvider); + + UnitMasterManagement unitMasterManagement = new UnitMasterManagement(); + String jsonResult = unitMasterManagement.getFittingUnits(getUnitDescription("", "")); + assertEquals("[]", jsonResult); + } + + @Test + public void getFittingUnitsUnits() throws Exception { + UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass()); + when(unitProvider.getUnit(anyString())).thenReturn(new Unit()); + + List unitList = new ArrayList<>(2); + Unit unit = new Unit(); + unit.setLabel("A"); + unit.setResource(new URI("http://A")); + unitList.add(unit); + unit = new Unit(); + unit.setLabel("A"); + unit.setResource(new URI("http://A")); + unitList.add(unit); + unitList.add(new Unit()); + + when(unitProvider.getUnitsByType(any())).thenReturn((unitList)); + Whitebox.setInternalState(UnitProvider.class, "INSTANCE", unitProvider); + + UnitMasterManagement unitMasterManagement = new UnitMasterManagement(); + String jsonResult = unitMasterManagement.getFittingUnits(getUnitDescription("", "")); + assertEquals("[{\"resource\":\"http://A\",\"label\":\"A\"},{\"resource\":\"http://A\",\"label\":\"A\"}]", + jsonResult); + } + + + private UnitDescription getUnitDescription(String label, String ressource) { + UnitDescription unitDescription = new UnitDescription(); + unitDescription.setLabel(label); + unitDescription.setResource(ressource); + return unitDescription; + } } diff --git a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/WorkerRestClientTest.java b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/WorkerRestClientTest.java index 401f8946d3..3e747196ac 100644 --- a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/WorkerRestClientTest.java +++ b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/WorkerRestClientTest.java @@ -22,6 +22,7 @@ import org.apache.streampipes.connect.container.master.util.WorkerPaths; import org.apache.streampipes.model.connect.adapter.GenericAdapterSetDescription; import org.apache.streampipes.model.connect.adapter.GenericAdapterStreamDescription; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,106 +31,111 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import static org.mockito.ArgumentMatchers.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; -import static org.powermock.api.mockito.PowerMockito.*; +import static org.powermock.api.mockito.PowerMockito.doNothing; +import static org.powermock.api.mockito.PowerMockito.doThrow; +import static org.powermock.api.mockito.PowerMockito.verifyStatic; +import static org.powermock.api.mockito.PowerMockito.when; @RunWith(PowerMockRunner.class) -@PrepareForTest({ WorkerRestClient.class, WorkerPaths.class }) +@PrepareForTest({WorkerRestClient.class, WorkerPaths.class}) @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) public class WorkerRestClientTest { - /** - * Notes: In this class I tested how powermock could be used to mok static methods - * One problem is to mock static methods that return void - */ + /** + * Notes: In this class I tested how powermock could be used to mok static methods + * One problem is to mock static methods that return void + */ - @Before - public void before() { - PowerMockito.mockStatic(WorkerRestClient.class); - PowerMockito.mockStatic(WorkerPaths.class); - } + @Before + public void before() { + PowerMockito.mockStatic(WorkerRestClient.class); + PowerMockito.mockStatic(WorkerPaths.class); + } - @Test - public void stopStreamAdapterSuccess() throws Exception { + @Test + public void stopStreamAdapterSuccess() throws Exception { - String expectedUrl = "worker/stream/stop"; - doNothing().when(WorkerRestClient.class, "stopAdapter", any(), anyString()); - when(WorkerRestClient.class, "stopStreamAdapter", anyString(), any()).thenCallRealMethod(); - when(WorkerPaths.class, "getStreamStopPath").thenReturn(expectedUrl); - GenericAdapterStreamDescription description = new GenericAdapterStreamDescription(); - description.setElementId("id1"); + String expectedUrl = "worker/stream/stop"; + doNothing().when(WorkerRestClient.class, "stopAdapter", any(), anyString()); + when(WorkerRestClient.class, "stopStreamAdapter", anyString(), any()).thenCallRealMethod(); + when(WorkerPaths.class, "getStreamStopPath").thenReturn(expectedUrl); + GenericAdapterStreamDescription description = new GenericAdapterStreamDescription(); + description.setElementId("id1"); - WorkerRestClient.stopStreamAdapter("", description); + WorkerRestClient.stopStreamAdapter("", description); - verifyStatic(WorkerRestClient.class, times(1)); - WorkerRestClient.stopAdapter(any(), eq(expectedUrl)); + verifyStatic(WorkerRestClient.class, times(1)); + WorkerRestClient.stopAdapter(any(), eq(expectedUrl)); - } + } - @Test(expected = AdapterException.class) - public void stopStreamAdapterFail() throws Exception { - doThrow(new AdapterException()).when(WorkerRestClient.class, "stopAdapter", any(), anyString()); - when(WorkerRestClient.class, "stopStreamAdapter", anyString(), any()).thenCallRealMethod(); + @Test(expected = AdapterException.class) + public void stopStreamAdapterFail() throws Exception { + doThrow(new AdapterException()).when(WorkerRestClient.class, "stopAdapter", any(), anyString()); + when(WorkerRestClient.class, "stopStreamAdapter", anyString(), any()).thenCallRealMethod(); - GenericAdapterStreamDescription description = new GenericAdapterStreamDescription(); - description.setElementId("id1"); + GenericAdapterStreamDescription description = new GenericAdapterStreamDescription(); + description.setElementId("id1"); - WorkerRestClient.stopStreamAdapter("", description); + WorkerRestClient.stopStreamAdapter("", description); - } + } - @Test - public void invokeSetAdapterSuccess() throws Exception { + @Test + public void invokeSetAdapterSuccess() throws Exception { - String expectedUrl = "worker/set/invoke"; - doNothing().when(WorkerRestClient.class, "startAdapter", anyString(), any()); - when(WorkerRestClient.class, "invokeSetAdapter", anyString(), any()).thenCallRealMethod(); - when(WorkerPaths.class, "getSetInvokePath").thenReturn(expectedUrl); + String expectedUrl = "worker/set/invoke"; + doNothing().when(WorkerRestClient.class, "startAdapter", anyString(), any()); + when(WorkerRestClient.class, "invokeSetAdapter", anyString(), any()).thenCallRealMethod(); + when(WorkerPaths.class, "getSetInvokePath").thenReturn(expectedUrl); - GenericAdapterSetDescription description = new GenericAdapterSetDescription(); - description.setElementId("id1"); - WorkerRestClient.invokeSetAdapter("", description); + GenericAdapterSetDescription description = new GenericAdapterSetDescription(); + description.setElementId("id1"); + WorkerRestClient.invokeSetAdapter("", description); - verifyStatic(WorkerRestClient.class, times(1)); - WorkerRestClient.startAdapter(eq("worker/set/invoke"), any()); + verifyStatic(WorkerRestClient.class, times(1)); + WorkerRestClient.startAdapter(eq("worker/set/invoke"), any()); - } + } - @Test(expected = AdapterException.class) - public void invokeSetAdapterFail() throws Exception { - doThrow(new AdapterException()).when(WorkerRestClient.class, "startAdapter", anyString(), any()); - when(WorkerRestClient.class, "invokeSetAdapter", anyString(), any()).thenCallRealMethod(); + @Test(expected = AdapterException.class) + public void invokeSetAdapterFail() throws Exception { + doThrow(new AdapterException()).when(WorkerRestClient.class, "startAdapter", anyString(), any()); + when(WorkerRestClient.class, "invokeSetAdapter", anyString(), any()).thenCallRealMethod(); - WorkerRestClient.invokeSetAdapter("", null); - } + WorkerRestClient.invokeSetAdapter("", null); + } - @Test - public void stopSetAdapterSuccess() throws Exception { + @Test + public void stopSetAdapterSuccess() throws Exception { - String expectedUrl = "worker/set/stop"; - doNothing().when(WorkerRestClient.class, "stopAdapter", any(), anyString()); - when(WorkerRestClient.class, "stopSetAdapter", anyString(), any()).thenCallRealMethod(); - when(WorkerPaths.class, "getSetStopPath").thenReturn(expectedUrl); + String expectedUrl = "worker/set/stop"; + doNothing().when(WorkerRestClient.class, "stopAdapter", any(), anyString()); + when(WorkerRestClient.class, "stopSetAdapter", anyString(), any()).thenCallRealMethod(); + when(WorkerPaths.class, "getSetStopPath").thenReturn(expectedUrl); - GenericAdapterSetDescription description = new GenericAdapterSetDescription(); - description.setElementId("id1"); - WorkerRestClient.stopSetAdapter("", description); + GenericAdapterSetDescription description = new GenericAdapterSetDescription(); + description.setElementId("id1"); + WorkerRestClient.stopSetAdapter("", description); - verifyStatic(WorkerRestClient.class, times(1)); - WorkerRestClient.stopAdapter(any(), eq(expectedUrl)); + verifyStatic(WorkerRestClient.class, times(1)); + WorkerRestClient.stopAdapter(any(), eq(expectedUrl)); - } + } - @Test(expected = AdapterException.class) - public void stopSetAdapterFail() throws Exception { - doThrow(new AdapterException()).when(WorkerRestClient.class, "stopAdapter", any(), anyString()); - when(WorkerRestClient.class, "stopSetAdapter", anyString(), any()).thenCallRealMethod(); + @Test(expected = AdapterException.class) + public void stopSetAdapterFail() throws Exception { + doThrow(new AdapterException()).when(WorkerRestClient.class, "stopAdapter", any(), anyString()); + when(WorkerRestClient.class, "stopSetAdapter", anyString(), any()).thenCallRealMethod(); - GenericAdapterSetDescription description = new GenericAdapterSetDescription(); - description.setElementId("id1"); - WorkerRestClient.stopSetAdapter("", description); + GenericAdapterSetDescription description = new GenericAdapterSetDescription(); + description.setElementId("id1"); + WorkerRestClient.stopSetAdapter("", description); - } + } } From 7795cf41690d8a187952fd18004fce71259bdc6b Mon Sep 17 00:00:00 2001 From: bossenti Date: Sun, 18 Dec 2022 20:47:00 +0100 Subject: [PATCH 2/5] add checkstyle to streampipes-platform-services --- streampipes-platform-services/pom.xml | 11 +- .../streampipes/ps/DataLakeImageResource.java | 3 +- .../ps/DataLakeMeasureResourceV3.java | 40 +- .../ps/DataLakeMeasureResourceV4.java | 101 +-- .../streampipes/ps/DataLakeResourceV3.java | 1 + .../streampipes/ps/DataLakeResourceV4.java | 583 +++++++++++------- .../ps/PipelineElementTemplateResource.java | 212 ++++--- 7 files changed, 558 insertions(+), 393 deletions(-) diff --git a/streampipes-platform-services/pom.xml b/streampipes-platform-services/pom.xml index d797eeda5a..f529b5017c 100644 --- a/streampipes-platform-services/pom.xml +++ b/streampipes-platform-services/pom.xml @@ -17,7 +17,8 @@ ~ --> - + streampipes-parent org.apache.streampipes @@ -60,4 +61,12 @@ + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + diff --git a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeImageResource.java b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeImageResource.java index f8a73e077e..3c20fc6b89 100644 --- a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeImageResource.java +++ b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeImageResource.java @@ -1,4 +1,3 @@ -package org.apache.streampipes.ps; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -17,6 +16,8 @@ * */ +package org.apache.streampipes.ps; + import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource; import org.apache.streampipes.storage.management.StorageDispatcher; diff --git a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeMeasureResourceV3.java b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeMeasureResourceV3.java index 877b88451d..41858cdbad 100644 --- a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeMeasureResourceV3.java +++ b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeMeasureResourceV3.java @@ -23,7 +23,11 @@ import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource; import org.apache.streampipes.rest.shared.annotation.JacksonSerialized; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -31,23 +35,23 @@ @Deprecated public class DataLakeMeasureResourceV3 extends AbstractAuthGuardedRestResource { - private DataLakeNoUserManagementV3 dataLakeManagement; - - public DataLakeMeasureResourceV3() { - this.dataLakeManagement = new DataLakeNoUserManagementV3(); + private DataLakeNoUserManagementV3 dataLakeManagement; + + public DataLakeMeasureResourceV3() { + this.dataLakeManagement = new DataLakeNoUserManagementV3(); + } + + @POST + @JacksonSerialized + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/{measure}") + public Response addDataLake(@PathParam("measure") String measure, EventSchema eventSchema) { + if (this.dataLakeManagement.addDataLake(measure, eventSchema)) { + return ok(); + } else { + return Response.status(409).build(); } - @POST - @JacksonSerialized - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @Path("/{measure}") - public Response addDataLake(@PathParam("measure") String measure, EventSchema eventSchema) { - if (this.dataLakeManagement.addDataLake(measure, eventSchema)) { - return ok(); - } else { - return Response.status(409).build(); - } - - } + } } diff --git a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeMeasureResourceV4.java b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeMeasureResourceV4.java index 636cf0c0d7..640633172f 100644 --- a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeMeasureResourceV4.java +++ b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeMeasureResourceV4.java @@ -23,64 +23,71 @@ import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource; import org.apache.streampipes.rest.shared.annotation.JacksonSerialized; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Path("/v4/datalake/measure") public class DataLakeMeasureResourceV4 extends AbstractAuthGuardedRestResource { - private DataLakeManagementV4 dataLakeManagement; + private DataLakeManagementV4 dataLakeManagement; - public DataLakeMeasureResourceV4() { - this.dataLakeManagement = new DataLakeManagementV4(); - } + public DataLakeMeasureResourceV4() { + this.dataLakeManagement = new DataLakeManagementV4(); + } - @POST - @JacksonSerialized - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @Path("/") - public Response addDataLake(DataLakeMeasure dataLakeMeasure) { - DataLakeMeasure result = this.dataLakeManagement.addDataLake(dataLakeMeasure); - return ok(result); - } + @POST + @JacksonSerialized + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @Path("/") + public Response addDataLake(DataLakeMeasure dataLakeMeasure) { + DataLakeMeasure result = this.dataLakeManagement.addDataLake(dataLakeMeasure); + return ok(result); + } - @GET - @JacksonSerialized - @Produces(MediaType.APPLICATION_JSON) - @Path("{id}") - public Response getDataLakeMeasure(@PathParam("id") String measureId) { - return ok(this.dataLakeManagement.getById(measureId)); - } + @GET + @JacksonSerialized + @Produces(MediaType.APPLICATION_JSON) + @Path("{id}") + public Response getDataLakeMeasure(@PathParam("id") String measureId) { + return ok(this.dataLakeManagement.getById(measureId)); + } - @PUT - @JacksonSerialized - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @Path("{id}") - public Response updateDataLakeMeasure(@PathParam("id") String measureId, - DataLakeMeasure measure) { - if (measureId.equals(measure.getElementId())) { - try { - this.dataLakeManagement.updateDataLake(measure); - return ok(); - } catch (IllegalArgumentException e) { - return badRequest(e.getMessage()); - } - } - return badRequest(); + @PUT + @JacksonSerialized + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @Path("{id}") + public Response updateDataLakeMeasure(@PathParam("id") String measureId, + DataLakeMeasure measure) { + if (measureId.equals(measure.getElementId())) { + try { + this.dataLakeManagement.updateDataLake(measure); + return ok(); + } catch (IllegalArgumentException e) { + return badRequest(e.getMessage()); + } } + return badRequest(); + } - @DELETE - @JacksonSerialized - @Path("{id}") - public Response deleteDataLakeMeasure(@PathParam("id") String measureId) { - try { - this.dataLakeManagement.deleteDataLakeMeasure(measureId); - return ok(); - } catch (IllegalArgumentException e) { - return badRequest(e.getMessage()); - } + @DELETE + @JacksonSerialized + @Path("{id}") + public Response deleteDataLakeMeasure(@PathParam("id") String measureId) { + try { + this.dataLakeManagement.deleteDataLakeMeasure(measureId); + return ok(); + } catch (IllegalArgumentException e) { + return badRequest(e.getMessage()); } + } } diff --git a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeResourceV3.java b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeResourceV3.java index 00fd8c9b7b..31d9c4ef12 100644 --- a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeResourceV3.java +++ b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeResourceV3.java @@ -28,6 +28,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; + import java.util.List; @Path("/v3/datalake") diff --git a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeResourceV4.java b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeResourceV4.java index dd75bd4459..955d9e20f3 100644 --- a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeResourceV4.java +++ b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeResourceV4.java @@ -18,260 +18,383 @@ package org.apache.streampipes.ps; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.apache.streampipes.dataexplorer.DataLakeManagementV4; import org.apache.streampipes.dataexplorer.v4.ProvidedQueryParams; import org.apache.streampipes.dataexplorer.v4.query.writer.OutputFormat; import org.apache.streampipes.model.StreamPipesErrorMessage; import org.apache.streampipes.model.datalake.DataLakeConfiguration; import org.apache.streampipes.model.datalake.DataLakeMeasure; -import org.apache.streampipes.rest.core.base.impl.AbstractRestResource; import org.apache.streampipes.model.datalake.DataSeries; import org.apache.streampipes.model.datalake.SpQueryResult; +import org.apache.streampipes.rest.core.base.impl.AbstractRestResource; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.ws.rs.*; -import javax.ws.rs.core.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.StreamingOutput; +import javax.ws.rs.core.UriInfo; + import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.*; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_AGGREGATION_FUNCTION; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_AUTO_AGGREGATE; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_COLUMNS; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_COUNT_ONLY; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_CSV_DELIMITER; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_END_DATE; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_FILTER; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_FORMAT; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_GROUP_BY; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_LIMIT; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_MAXIMUM_AMOUNT_OF_EVENTS; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_MISSING_VALUE_BEHAVIOUR; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_OFFSET; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_ORDER; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_PAGE; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_START_DATE; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_TIME_INTERVAL; +import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.SUPPORTED_PARAMS; @Path("v4/datalake") public class DataLakeResourceV4 extends AbstractRestResource { - private static final Logger logger = LoggerFactory.getLogger(DataLakeResourceV4.class); - - private DataLakeManagementV4 dataLakeManagement; - - public DataLakeResourceV4() { - this.dataLakeManagement = new DataLakeManagementV4(); - } - - public DataLakeResourceV4(DataLakeManagementV4 dataLakeManagement) { - this.dataLakeManagement = dataLakeManagement; - } - - - @POST - @Path("/configuration") - @Consumes(MediaType.APPLICATION_JSON) - @Operation(summary = "Configure the parameters of the data lake", tags = {"Data Lake"}, - responses = {@ApiResponse(responseCode = "200", description = "Configuration was successful")}) - public Response configureMeasurement(@Parameter(in = ParameterIn.QUERY, description = "should any parameter be reset to its default value?") @DefaultValue("false") @QueryParam("resetToDefault") boolean resetToDefault, - @Parameter(in = ParameterIn.DEFAULT, description = "the configuration parameters") DataLakeConfiguration config) { - return ok(this.dataLakeManagement.editMeasurementConfiguration(config, resetToDefault)); - } - - @DELETE - @Path("/measurements/{measurementID}") - @Operation(summary = "Remove data from a single measurement series with given id", tags = {"Data Lake"}, - responses = { - @ApiResponse(responseCode = "200", description = "Data from measurement series successfully removed"), - @ApiResponse(responseCode = "400", description = "Measurement series with given id not found")}) - public Response deleteData(@Parameter(in = ParameterIn.PATH, description = "the id of the measurement series", required = true) @PathParam("measurementID") String measurementID - , @Parameter(in = ParameterIn.QUERY, description = "start date for slicing operation") @QueryParam("startDate") Long startDate - , @Parameter(in = ParameterIn.QUERY, description = "end date for slicing operation") @QueryParam("endDate") Long endDate) { - - SpQueryResult result = this.dataLakeManagement.deleteData(measurementID, startDate, endDate); + private static final Logger logger = LoggerFactory.getLogger(DataLakeResourceV4.class); + + private DataLakeManagementV4 dataLakeManagement; + + public DataLakeResourceV4() { + this.dataLakeManagement = new DataLakeManagementV4(); + } + + public DataLakeResourceV4(DataLakeManagementV4 dataLakeManagement) { + this.dataLakeManagement = dataLakeManagement; + } + + + @POST + @Path("/configuration") + @Consumes(MediaType.APPLICATION_JSON) + @Operation(summary = "Configure the parameters of the data lake", tags = {"Data Lake"}, + responses = {@ApiResponse(responseCode = "200", description = "Configuration was successful")}) + public Response configureMeasurement( + @Parameter(in = ParameterIn.QUERY, description = "should any parameter be reset to its default value?") + @DefaultValue("false") @QueryParam("resetToDefault") boolean resetToDefault, + @Parameter(in = ParameterIn.DEFAULT, description = "the configuration parameters") DataLakeConfiguration config) { + return ok(this.dataLakeManagement.editMeasurementConfiguration(config, resetToDefault)); + } + + @DELETE + @Path("/measurements/{measurementID}") + @Operation(summary = "Remove data from a single measurement series with given id", tags = {"Data Lake"}, + responses = { + @ApiResponse(responseCode = "200", description = "Data from measurement series successfully removed"), + @ApiResponse(responseCode = "400", description = "Measurement series with given id not found")}) + public Response deleteData( + @Parameter(in = ParameterIn.PATH, description = "the id of the measurement series", required = true) + @PathParam("measurementID") String measurementID + , @Parameter(in = ParameterIn.QUERY, description = "start date for slicing operation") @QueryParam("startDate") + Long startDate + , @Parameter(in = ParameterIn.QUERY, description = "end date for slicing operation") @QueryParam("endDate") + Long endDate) { + + SpQueryResult result = this.dataLakeManagement.deleteData(measurementID, startDate, endDate); + return ok(); + } + + @DELETE + @Path("/measurements/{measurementID}/drop") + @Operation(summary = "Drop a single measurement series with given id from Data Lake and " + + "remove related event property", + tags = { + "Data Lake"}, + responses = { + @ApiResponse( + responseCode = "200", + description = "Measurement series successfully dropped from Data Lake"), + @ApiResponse( + responseCode = "400", + description = "Measurement series with given id or related event property not found")}) + public Response dropMeasurementSeries( + @Parameter(in = ParameterIn.PATH, description = "the id of the measurement series", required = true) + @PathParam("measurementID") String measurementID) { + + boolean isSuccessDataLake = this.dataLakeManagement.removeMeasurement(measurementID); + + if (isSuccessDataLake) { + boolean isSuccessEventProperty = this.dataLakeManagement.removeEventProperty(measurementID); + if (isSuccessEventProperty) { return ok(); + } else { + return Response.status(Response.Status.NOT_FOUND) + .entity("Event property related to measurement series with given id not found.").build(); + } + } else { + return Response.status(Response.Status.NOT_FOUND).entity("Measurement series with given id not found.").build(); } - - @DELETE - @Path("/measurements/{measurementID}/drop") - @Operation(summary = "Drop a single measurement series with given id from Data Lake and remove related event property", tags = {"Data Lake"}, - responses = { - @ApiResponse(responseCode = "200", description = "Measurement series successfully dropped from Data Lake"), - @ApiResponse(responseCode = "400", description = "Measurement series with given id or related event property not found")}) - public Response dropMeasurementSeries(@Parameter(in = ParameterIn.PATH, description = "the id of the measurement series", required = true) @PathParam("measurementID") String measurementID) { - - boolean isSuccessDataLake = this.dataLakeManagement.removeMeasurement(measurementID); - - if (isSuccessDataLake) { - boolean isSuccessEventProperty = this.dataLakeManagement.removeEventProperty(measurementID); - if (isSuccessEventProperty) { - return ok(); - } else { - return Response.status(Response.Status.NOT_FOUND).entity("Event property related to measurement series with given id not found.").build(); - } - } else { - return Response.status(Response.Status.NOT_FOUND).entity("Measurement series with given id not found.").build(); - } - } - - @GET - @Path("/measurements") - @Produces(MediaType.APPLICATION_JSON) - @Operation(summary = "Get a list of all measurement series", tags = {"Data Lake"}, - responses = { - @ApiResponse(responseCode = "200", description = "array of stored measurement series", content = @Content(array = @ArraySchema(schema = @Schema(implementation = DataLakeMeasure.class))))}) - public Response getAll() { - List allMeasurements = this.dataLakeManagement.getAllMeasurements(); - return ok(allMeasurements); - } - - @GET - @Path("/measurements/{measurementId}/tags") - @Produces(MediaType.APPLICATION_JSON) - public Response getTagValues(@PathParam("measurementId") String measurementId, - @QueryParam("fields") String fields) { - Map tagValues = dataLakeManagement.getTagValues(measurementId, fields); - return ok(tagValues); - } - - - @GET - @Path("/measurements/{measurementID}") - @Produces(MediaType.APPLICATION_JSON) - @Operation(summary = "Get data from a single measurement series by a given id", tags = {"Data Lake"}, - responses = { - @ApiResponse(responseCode = "400", description = "Measurement series with given id and requested query specification not found"), - @ApiResponse(responseCode = "200", description = "requested data", content = @Content(schema = @Schema(implementation = DataSeries.class)))}) - public Response getData(@Parameter(in = ParameterIn.PATH, description = "the id of the measurement series", required = true) @PathParam("measurementID") String measurementID - , @Parameter(in = ParameterIn.QUERY, description = "the columns to be selected (comma-separated)") @QueryParam(QP_COLUMNS) String columns - , @Parameter(in = ParameterIn.QUERY, description = "start date for slicing operation") @QueryParam(QP_START_DATE) Long startDate - , @Parameter(in = ParameterIn.QUERY, description = "end date for slicing operation") @QueryParam(QP_END_DATE) Long endDate - , @Parameter(in = ParameterIn.QUERY, description = "page number for paging operation") @QueryParam(QP_PAGE) Integer page - , @Parameter(in = ParameterIn.QUERY, description = "maximum number of retrieved query results") @QueryParam(QP_LIMIT) Integer limit - , @Parameter(in = ParameterIn.QUERY, description = "offset") @QueryParam(QP_OFFSET) Integer offset - , @Parameter(in = ParameterIn.QUERY, description = "grouping tags (comma-separated) for grouping operation") @QueryParam(QP_GROUP_BY) String groupBy - , @Parameter(in = ParameterIn.QUERY, description = "ordering of retrieved query results (ASC or DESC - default is ASC)") @QueryParam(QP_ORDER) String order - , @Parameter(in = ParameterIn.QUERY, description = "name of aggregation function used for grouping operation") @QueryParam(QP_AGGREGATION_FUNCTION) String aggregationFunction - , @Parameter(in = ParameterIn.QUERY, description = "time interval for aggregation (e.g. 1m - one minute) for grouping operation") @QueryParam(QP_TIME_INTERVAL) String timeInterval - , @Parameter(in = ParameterIn.QUERY, description = "only return the number of results") @QueryParam(QP_COUNT_ONLY) String countOnly - , @Parameter(in = ParameterIn.QUERY, description = "auto-aggregate the number of results to avoid browser overload") @QueryParam(QP_AUTO_AGGREGATE) boolean autoAggregate - , @Parameter(in = ParameterIn.QUERY, description = "filter conditions (a comma-separated list of filter conditions such as [field,operator,condition])") @QueryParam(QP_FILTER) String filter - , @Parameter(in = ParameterIn.QUERY, description = "missingValueBehaviour (ignore or empty)") @QueryParam(QP_MISSING_VALUE_BEHAVIOUR) String missingValueBehaviour - , @Parameter(in = ParameterIn.QUERY, description = "the maximum amount of resulting events, when too high the query status is set to TOO_MUCH_DATA") @QueryParam(QP_MAXIMUM_AMOUNT_OF_EVENTS) Integer maximumAmountOfResults - , @Context UriInfo uriInfo) { - - MultivaluedMap queryParams = uriInfo.getQueryParameters(); - - if (!(checkProvidedQueryParams(queryParams))) { - return badRequest(); - } else { - ProvidedQueryParams sanitizedParams = populate(measurementID, queryParams); - try { - SpQueryResult result = - this.dataLakeManagement.getData(sanitizedParams, isIgnoreMissingValues(missingValueBehaviour)); - return ok(result); - } catch (RuntimeException e) { - return badRequest(StreamPipesErrorMessage.from(e)); - } - } - } - - @POST - @Path("/query") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - public Response getData(List> queryParams) { - var results = queryParams - .stream() - .map(qp -> new ProvidedQueryParams(qp.get("measureName"), qp)) - .map(params -> this.dataLakeManagement.getData(params, true)) - .collect(Collectors.toList()); - - return ok(results); - } - - @GET - @Path("/measurements/{measurementID}/download") - @Produces(MediaType.APPLICATION_OCTET_STREAM) - @Operation(summary = "Download data from a single measurement series by a given id", tags = {"Data Lake"}, - responses = { - @ApiResponse(responseCode = "400", description = "Measurement series with given id and requested query specification not found"), - @ApiResponse(responseCode = "200", description = "requested data", content = @Content(schema = @Schema(implementation = DataSeries.class)))}) - public Response downloadData(@Parameter(in = ParameterIn.PATH, description = "the id of the measurement series", required = true) @PathParam("measurementID") String measurementID - , @Parameter(in = ParameterIn.QUERY, description = "the columns to be selected (comma-separated)") @QueryParam(QP_COLUMNS) String columns - , @Parameter(in = ParameterIn.QUERY, description = "start date for slicing operation") @QueryParam(QP_START_DATE) Long startDate - , @Parameter(in = ParameterIn.QUERY, description = "end date for slicing operation") @QueryParam(QP_END_DATE) Long endDate - , @Parameter(in = ParameterIn.QUERY, description = "page number for paging operation") @QueryParam(QP_PAGE) Integer page - , @Parameter(in = ParameterIn.QUERY, description = "maximum number of retrieved query results") @QueryParam(QP_LIMIT) Integer limit - , @Parameter(in = ParameterIn.QUERY, description = "offset") @QueryParam(QP_OFFSET) Integer offset - , @Parameter(in = ParameterIn.QUERY, description = "grouping tags (comma-separated) for grouping operation") @QueryParam(QP_GROUP_BY) String groupBy - , @Parameter(in = ParameterIn.QUERY, description = "ordering of retrieved query results (ASC or DESC - default is ASC)") @QueryParam(QP_ORDER) String order - , @Parameter(in = ParameterIn.QUERY, description = "name of aggregation function used for grouping operation") @QueryParam(QP_AGGREGATION_FUNCTION) String aggregationFunction - , @Parameter(in = ParameterIn.QUERY, description = "time interval for aggregation (e.g. 1m - one minute) for grouping operation") @QueryParam(QP_TIME_INTERVAL) String timeInterval - , @Parameter(in = ParameterIn.QUERY, description = "format specification (csv, json - default is csv) for data download") @QueryParam(QP_FORMAT) String format - , @Parameter(in = ParameterIn.QUERY, description = "csv delimiter (comma or semicolon)") @QueryParam(QP_CSV_DELIMITER) String csvDelimiter - , @Parameter(in = ParameterIn.QUERY, description = "missingValueBehaviour (ignore or empty)") @QueryParam(QP_MISSING_VALUE_BEHAVIOUR) String missingValueBehaviour - , @Parameter(in = ParameterIn.QUERY, description = "filter conditions (a comma-separated list of filter conditions such as [field,operator,condition])") @QueryParam(QP_FILTER) String filter - , @Context UriInfo uriInfo) { - - MultivaluedMap queryParams = uriInfo.getQueryParameters(); - - if (!(checkProvidedQueryParams(queryParams))) { - return badRequest(); - } else { - ProvidedQueryParams sanitizedParams = populate(measurementID, queryParams); - if (format == null) { - format = "csv"; - } - - OutputFormat outputFormat = format.equals("csv") ? OutputFormat.CSV : OutputFormat.JSON; - StreamingOutput streamingOutput = output -> dataLakeManagement.getDataAsStream( - sanitizedParams, - outputFormat, - isIgnoreMissingValues(missingValueBehaviour), - output); - - return Response.ok(streamingOutput, MediaType.APPLICATION_OCTET_STREAM). - header("Content-Disposition", "attachment; filename=\"datalake." + outputFormat + "\"") - .build(); - } - } - - - @GET - @Path("/configuration") - @Produces(MediaType.APPLICATION_JSON) - @Operation(summary = "Get the configuration parameters of the data lake", tags = {"Data Lake"}, - responses = { - @ApiResponse(responseCode = "200", description = "configuration parameters", content = @Content(schema = @Schema(implementation = DataLakeConfiguration.class)))}) - public Response getMeasurementConfiguration(@Parameter(in = ParameterIn.QUERY, description = "the id of a specific configuration parameter") @QueryParam("parameterID") String parameterID) { - return ok(this.dataLakeManagement.getDataLakeConfiguration()); - } - - @DELETE - @Path("/measurements") - @Operation(summary = "Remove all stored measurement series from Data Lake", tags = {"Data Lake"}, - responses = { - @ApiResponse(responseCode = "200", description = "All measurement series successfully removed")}) - public Response removeAll() { - boolean isSuccess = this.dataLakeManagement.removeAllMeasurements(); - return Response.ok(isSuccess).build(); - } - - private boolean checkProvidedQueryParams(MultivaluedMap providedParams) { - return SUPPORTED_PARAMS.containsAll(providedParams.keySet()); + } + + @GET + @Path("/measurements") + @Produces(MediaType.APPLICATION_JSON) + @Operation(summary = "Get a list of all measurement series", tags = {"Data Lake"}, + responses = { + @ApiResponse( + responseCode = "200", + description = "array of stored measurement series", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = DataLakeMeasure.class))))}) + public Response getAll() { + List allMeasurements = this.dataLakeManagement.getAllMeasurements(); + return ok(allMeasurements); + } + + @GET + @Path("/measurements/{measurementId}/tags") + @Produces(MediaType.APPLICATION_JSON) + public Response getTagValues(@PathParam("measurementId") String measurementId, + @QueryParam("fields") String fields) { + Map tagValues = dataLakeManagement.getTagValues(measurementId, fields); + return ok(tagValues); + } + + + @GET + @Path("/measurements/{measurementID}") + @Produces(MediaType.APPLICATION_JSON) + @Operation(summary = "Get data from a single measurement series by a given id", tags = {"Data Lake"}, + responses = { + @ApiResponse( + responseCode = "400", + description = "Measurement series with given id and requested query specification not found"), + @ApiResponse( + responseCode = "200", + description = "requested data", content = @Content(schema = @Schema(implementation = DataSeries.class)))}) + public Response getData( + @Parameter(in = ParameterIn.PATH, description = "the id of the measurement series", required = true) + @PathParam("measurementID") String measurementID + , @Parameter(in = ParameterIn.QUERY, description = "the columns to be selected (comma-separated)") + @QueryParam(QP_COLUMNS) String columns + , @Parameter(in = ParameterIn.QUERY, description = "start date for slicing operation") @QueryParam(QP_START_DATE) + Long startDate + , @Parameter(in = ParameterIn.QUERY, description = "end date for slicing operation") @QueryParam(QP_END_DATE) + Long endDate + , @Parameter(in = ParameterIn.QUERY, description = "page number for paging operation") @QueryParam(QP_PAGE) + Integer page + , @Parameter(in = ParameterIn.QUERY, description = "maximum number of retrieved query results") + @QueryParam(QP_LIMIT) Integer limit + , @Parameter(in = ParameterIn.QUERY, description = "offset") @QueryParam(QP_OFFSET) Integer offset + , @Parameter(in = ParameterIn.QUERY, description = "grouping tags (comma-separated) for grouping operation") + @QueryParam(QP_GROUP_BY) String groupBy + , + @Parameter( + in = ParameterIn.QUERY, + description = "ordering of retrieved query results (ASC or DESC - default is ASC)") + @QueryParam(QP_ORDER) String order + , @Parameter(in = ParameterIn.QUERY, description = "name of aggregation function used for grouping operation") + @QueryParam(QP_AGGREGATION_FUNCTION) String aggregationFunction + , + @Parameter( + in = ParameterIn.QUERY, + description = "time interval for aggregation (e.g. 1m - one minute) for grouping operation") + @QueryParam(QP_TIME_INTERVAL) String timeInterval + , @Parameter(in = ParameterIn.QUERY, description = "only return the number of results") @QueryParam(QP_COUNT_ONLY) + String countOnly + , + @Parameter(in = ParameterIn.QUERY, description = "auto-aggregate the number of results to avoid browser overload") + @QueryParam(QP_AUTO_AGGREGATE) boolean autoAggregate + , + @Parameter( + in = ParameterIn.QUERY, + description = "filter conditions (a comma-separated list of filter conditions" + + "such as [field,operator,condition])") + @QueryParam(QP_FILTER) String filter + , @Parameter(in = ParameterIn.QUERY, description = "missingValueBehaviour (ignore or empty)") + @QueryParam(QP_MISSING_VALUE_BEHAVIOUR) String missingValueBehaviour + , + @Parameter( + in = ParameterIn.QUERY, + description = "the maximum amount of resulting events," + + "when too high the query status is set to TOO_MUCH_DATA") + @QueryParam(QP_MAXIMUM_AMOUNT_OF_EVENTS) Integer maximumAmountOfResults + , @Context UriInfo uriInfo) { + + MultivaluedMap queryParams = uriInfo.getQueryParameters(); + + if (!(checkProvidedQueryParams(queryParams))) { + return badRequest(); + } else { + ProvidedQueryParams sanitizedParams = populate(measurementID, queryParams); + try { + SpQueryResult result = + this.dataLakeManagement.getData(sanitizedParams, isIgnoreMissingValues(missingValueBehaviour)); + return ok(result); + } catch (RuntimeException e) { + return badRequest(StreamPipesErrorMessage.from(e)); + } } - - private ProvidedQueryParams populate(String measurementId, MultivaluedMap rawParams) { - Map queryParamMap = new HashMap<>(); - rawParams.forEach((key, value) -> queryParamMap.put(key, String.join(",", value))); - - return new ProvidedQueryParams(measurementId, queryParamMap); + } + + @POST + @Path("/query") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response getData(List> queryParams) { + var results = queryParams + .stream() + .map(qp -> new ProvidedQueryParams(qp.get("measureName"), qp)) + .map(params -> this.dataLakeManagement.getData(params, true)) + .collect(Collectors.toList()); + + return ok(results); + } + + @GET + @Path("/measurements/{measurementID}/download") + @Produces(MediaType.APPLICATION_OCTET_STREAM) + @Operation(summary = "Download data from a single measurement series by a given id", tags = {"Data Lake"}, + responses = { + @ApiResponse( + responseCode = "400", + description = "Measurement series with given id and requested query specification not found"), + @ApiResponse( + responseCode = "200", + description = "requested data", content = @Content(schema = @Schema(implementation = DataSeries.class)))}) + public Response downloadData( + @Parameter(in = ParameterIn.PATH, description = "the id of the measurement series", required = true) + @PathParam("measurementID") String measurementID + , @Parameter(in = ParameterIn.QUERY, description = "the columns to be selected (comma-separated)") + @QueryParam(QP_COLUMNS) String columns + , @Parameter(in = ParameterIn.QUERY, description = "start date for slicing operation") @QueryParam(QP_START_DATE) + Long startDate + , @Parameter(in = ParameterIn.QUERY, description = "end date for slicing operation") @QueryParam(QP_END_DATE) + Long endDate + , @Parameter(in = ParameterIn.QUERY, description = "page number for paging operation") @QueryParam(QP_PAGE) + Integer page + , @Parameter(in = ParameterIn.QUERY, description = "maximum number of retrieved query results") + @QueryParam(QP_LIMIT) Integer limit + , @Parameter(in = ParameterIn.QUERY, description = "offset") @QueryParam(QP_OFFSET) Integer offset + , @Parameter(in = ParameterIn.QUERY, description = "grouping tags (comma-separated) for grouping operation") + @QueryParam(QP_GROUP_BY) String groupBy + , + @Parameter( + in = ParameterIn.QUERY, + description = "ordering of retrieved query results (ASC or DESC - default is ASC)") + @QueryParam(QP_ORDER) String order + , @Parameter(in = ParameterIn.QUERY, description = "name of aggregation function used for grouping operation") + @QueryParam(QP_AGGREGATION_FUNCTION) String aggregationFunction + , + @Parameter( + in = ParameterIn.QUERY, + description = "time interval for aggregation (e.g. 1m - one minute) for grouping operation") + @QueryParam(QP_TIME_INTERVAL) String timeInterval + , + @Parameter( + in = ParameterIn.QUERY, + description = "format specification (csv, json - default is csv) for data download") + @QueryParam(QP_FORMAT) String format + , @Parameter(in = ParameterIn.QUERY, description = "csv delimiter (comma or semicolon)") + @QueryParam(QP_CSV_DELIMITER) String csvDelimiter + , @Parameter(in = ParameterIn.QUERY, description = "missingValueBehaviour (ignore or empty)") + @QueryParam(QP_MISSING_VALUE_BEHAVIOUR) String missingValueBehaviour + , + @Parameter( + in = ParameterIn.QUERY, + description = "filter conditions (a comma-separated list of filter conditions" + + "such as [field,operator,condition])") + @QueryParam(QP_FILTER) String filter + , @Context UriInfo uriInfo) { + + MultivaluedMap queryParams = uriInfo.getQueryParameters(); + + if (!(checkProvidedQueryParams(queryParams))) { + return badRequest(); + } else { + ProvidedQueryParams sanitizedParams = populate(measurementID, queryParams); + if (format == null) { + format = "csv"; + } + + OutputFormat outputFormat = format.equals("csv") ? OutputFormat.CSV : OutputFormat.JSON; + StreamingOutput streamingOutput = output -> dataLakeManagement.getDataAsStream( + sanitizedParams, + outputFormat, + isIgnoreMissingValues(missingValueBehaviour), + output); + + return Response.ok(streamingOutput, MediaType.APPLICATION_OCTET_STREAM). + header("Content-Disposition", "attachment; filename=\"datalake." + outputFormat + "\"") + .build(); } - - // Checks if the parameter for missing value behaviour is set - private boolean isIgnoreMissingValues(String missingValueBehaviour) { - boolean ignoreMissingValues; - if ("ignore".equals(missingValueBehaviour)) { - ignoreMissingValues = true; - } else { - ignoreMissingValues = false; - } - return ignoreMissingValues; + } + + + @GET + @Path("/configuration") + @Produces(MediaType.APPLICATION_JSON) + @Operation(summary = "Get the configuration parameters of the data lake", tags = {"Data Lake"}, + responses = { + @ApiResponse( + responseCode = "200", + description = "configuration parameters", + content = @Content(schema = @Schema(implementation = DataLakeConfiguration.class)))}) + public Response getMeasurementConfiguration( + @Parameter(in = ParameterIn.QUERY, description = "the id of a specific configuration parameter") + @QueryParam("parameterID") String parameterID) { + return ok(this.dataLakeManagement.getDataLakeConfiguration()); + } + + @DELETE + @Path("/measurements") + @Operation(summary = "Remove all stored measurement series from Data Lake", tags = {"Data Lake"}, + responses = { + @ApiResponse(responseCode = "200", description = "All measurement series successfully removed")}) + public Response removeAll() { + boolean isSuccess = this.dataLakeManagement.removeAllMeasurements(); + return Response.ok(isSuccess).build(); + } + + private boolean checkProvidedQueryParams(MultivaluedMap providedParams) { + return SUPPORTED_PARAMS.containsAll(providedParams.keySet()); + } + + private ProvidedQueryParams populate(String measurementId, MultivaluedMap rawParams) { + Map queryParamMap = new HashMap<>(); + rawParams.forEach((key, value) -> queryParamMap.put(key, String.join(",", value))); + + return new ProvidedQueryParams(measurementId, queryParamMap); + } + + // Checks if the parameter for missing value behaviour is set + private boolean isIgnoreMissingValues(String missingValueBehaviour) { + boolean ignoreMissingValues; + if ("ignore".equals(missingValueBehaviour)) { + ignoreMissingValues = true; + } else { + ignoreMissingValues = false; } + return ignoreMissingValues; + } } diff --git a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/PipelineElementTemplateResource.java b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/PipelineElementTemplateResource.java index d159e2e463..79c577d759 100644 --- a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/PipelineElementTemplateResource.java +++ b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/PipelineElementTemplateResource.java @@ -17,13 +17,6 @@ */ package org.apache.streampipes.ps; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.parameters.RequestBody; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.apache.streampipes.manager.template.AdapterTemplateHandler; import org.apache.streampipes.manager.template.DataProcessorTemplateHandler; import org.apache.streampipes.manager.template.DataSinkTemplateHandler; @@ -34,7 +27,23 @@ import org.apache.streampipes.rest.core.base.impl.AbstractRestResource; import org.apache.streampipes.rest.shared.annotation.JacksonSerialized; -import javax.ws.rs.*; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -45,14 +54,14 @@ public class PipelineElementTemplateResource extends AbstractRestResource { @Produces(MediaType.APPLICATION_JSON) @JacksonSerialized @Operation(summary = "Get a list of all pipeline element templates", - tags = {"Pipeline Element Templates"}, - responses = { - @ApiResponse(content = { - @Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = PipelineElementTemplate.class))) - }) + tags = {"Pipeline Element Templates"}, + responses = { + @ApiResponse(content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = PipelineElementTemplate.class))) }) + }) public Response getAll(@Parameter(description = "Filter all templates by this appId") @QueryParam("appId") String appId) { if (appId == null) { @@ -67,15 +76,15 @@ public Response getAll(@Parameter(description = "Filter all templates by this ap @Produces(MediaType.APPLICATION_JSON) @JacksonSerialized @Operation(summary = "Get a single pipeline element template by a given id", - tags = {"Pipeline Element Templates"}, - responses = { - @ApiResponse(content = { - @Content( - mediaType = "application/json", - schema = @Schema(implementation = PipelineElementTemplate.class)) - }), - @ApiResponse(responseCode = "400", description = "Template with given id not found") - }) + tags = {"Pipeline Element Templates"}, + responses = { + @ApiResponse(content = { + @Content( + mediaType = "application/json", + schema = @Schema(implementation = PipelineElementTemplate.class)) + }), + @ApiResponse(responseCode = "400", description = "Template with given id not found") + }) public Response getById(@Parameter(description = "The id of the pipeline element template", required = true) @PathParam("id") String s) { try { @@ -89,12 +98,13 @@ public Response getById(@Parameter(description = "The id of the pipeline element @Consumes(MediaType.APPLICATION_JSON) @JacksonSerialized @Operation(summary = "Store a new pipeline element template", - tags = {"Pipeline Element Templates"}, - responses = { - @ApiResponse(responseCode = "200", description = "Template successfully stored") - }) + tags = {"Pipeline Element Templates"}, + responses = { + @ApiResponse(responseCode = "200", description = "Template successfully stored") + }) public Response create(@RequestBody(description = "The pipeline element template to be stored", - content = @Content(schema = @Schema(implementation = PipelineElementTemplate.class))) PipelineElementTemplate entity) { + content = @Content(schema = @Schema(implementation = PipelineElementTemplate.class))) + PipelineElementTemplate entity) { getPipelineElementTemplateStorage().createElement(entity); return ok(); } @@ -105,15 +115,15 @@ public Response create(@RequestBody(description = "The pipeline element template @Consumes(MediaType.APPLICATION_JSON) @JacksonSerialized @Operation(summary = "Update a pipeline element template", - tags = {"Pipeline Element Templates"}, - responses = { - @ApiResponse(content = { - @Content( - mediaType = "application/json", - schema = @Schema(implementation = PipelineElementTemplate.class)) - }, responseCode = "200", description = "Template successfully updated"), - @ApiResponse(responseCode = "400", description = "Template with given id not found") - }) + tags = {"Pipeline Element Templates"}, + responses = { + @ApiResponse(content = { + @Content( + mediaType = "application/json", + schema = @Schema(implementation = PipelineElementTemplate.class)) + }, responseCode = "200", description = "Template successfully updated"), + @ApiResponse(responseCode = "400", description = "Template with given id not found") + }) public Response update(@Parameter(description = "The id of the pipeline element template", required = true) @PathParam("id") String id, PipelineElementTemplate entity) { try { @@ -130,11 +140,11 @@ public Response update(@Parameter(description = "The id of the pipeline element @DELETE @Path("{id}") @Operation(summary = "Delete a pipeline element template by a given id", - tags = {"Pipeline Element Templates"}, - responses = { - @ApiResponse(responseCode = "200", description = "Pipeline element template successfully deleted"), - @ApiResponse(responseCode = "400", description = "Template with given id not found") - }) + tags = {"Pipeline Element Templates"}, + responses = { + @ApiResponse(responseCode = "200", description = "Pipeline element template successfully deleted"), + @ApiResponse(responseCode = "400", description = "Template with given id not found") + }) public Response delete(@Parameter(description = "The id of the pipeline element template", required = true) @PathParam("id") String s) { PipelineElementTemplate template = getPipelineElementTemplateStorage().getElementById(s); @@ -148,25 +158,29 @@ public Response delete(@Parameter(description = "The id of the pipeline element @Consumes(MediaType.APPLICATION_JSON) @JacksonSerialized @Operation(summary = "Configure a data sink with a pipeline element template.", - tags = {"Pipeline Element Templates"}, - responses = { - @ApiResponse(content = { - @Content( - mediaType = "application/json", - schema = @Schema(implementation = DataSinkInvocation.class)) - }, responseCode = "200", description = "The configured data sink invocation model"), - }) - public Response getPipelineElementForTemplate(@Parameter(description = "The id of the pipeline element template", required = true) - @PathParam("id") String id, - - @Parameter(description = "Overwrite the name and description of the pipeline element with the labels given in the pipeline element template") - @QueryParam("overwriteNames") String overwriteNameAndDescription, - - @RequestBody(description = "The data sink invocation that should be configured with the template contents", - content = @Content(schema = @Schema(implementation = DataSinkInvocation.class))) DataSinkInvocation invocation) { + tags = {"Pipeline Element Templates"}, + responses = { + @ApiResponse(content = { + @Content( + mediaType = "application/json", + schema = @Schema(implementation = DataSinkInvocation.class)) + }, responseCode = "200", description = "The configured data sink invocation model"), + }) + public Response getPipelineElementForTemplate( + @Parameter(description = "The id of the pipeline element template", required = true) + @PathParam("id") String id, + + @Parameter( + description = "Overwrite the name and description of the pipeline element" + + "with the labels given in the pipeline element template") + @QueryParam("overwriteNames") String overwriteNameAndDescription, + + @RequestBody(description = "The data sink invocation that should be configured with the template contents", + content = @Content(schema = @Schema(implementation = DataSinkInvocation.class))) + DataSinkInvocation invocation) { PipelineElementTemplate template = getPipelineElementTemplateStorage().getElementById(id); return ok(new DataSinkTemplateHandler(template, invocation, Boolean.parseBoolean(overwriteNameAndDescription)) - .applyTemplateOnPipelineElement()); + .applyTemplateOnPipelineElement()); } @POST @@ -175,26 +189,28 @@ public Response getPipelineElementForTemplate(@Parameter(description = "The id o @Consumes(MediaType.APPLICATION_JSON) @JacksonSerialized @Operation(summary = "Configure a data processor with a pipeline element template.", - tags = {"Pipeline Element Templates"}, - responses = { - @ApiResponse(content = { - @Content( - mediaType = "application/json", - schema = @Schema(implementation = DataProcessorInvocation.class)) - }, responseCode = "200", description = "The configured data processor invocation model"), - }) - public Response getPipelineElementForTemplate(@Parameter(description = "The id of the pipeline element template", required = true) - @PathParam("id") String id, - - @Parameter(description = "Overwrite the name and description of the pipeline element with the labels given in the pipeline element template") - @QueryParam("overwriteNames") String overwriteNameAndDescription, - - @RequestBody(description = "The data processor invocation that should be configured with the template contents", - content = @Content(schema = @Schema(implementation = DataProcessorInvocation.class))) - DataProcessorInvocation invocation) { + tags = {"Pipeline Element Templates"}, + responses = { + @ApiResponse(content = { + @Content( + mediaType = "application/json", + schema = @Schema(implementation = DataProcessorInvocation.class)) + }, responseCode = "200", description = "The configured data processor invocation model"), + }) + public Response getPipelineElementForTemplate( + @Parameter(description = "The id of the pipeline element template", required = true) + @PathParam("id") String id, + + @Parameter(description = "Overwrite the name and description of the pipeline element with" + + "the labels given in the pipeline element template") + @QueryParam("overwriteNames") String overwriteNameAndDescription, + + @RequestBody(description = "The data processor invocation that should be configured with the template contents", + content = @Content(schema = @Schema(implementation = DataProcessorInvocation.class))) + DataProcessorInvocation invocation) { PipelineElementTemplate template = getPipelineElementTemplateStorage().getElementById(id); return ok(new DataProcessorTemplateHandler(template, invocation, Boolean.parseBoolean(overwriteNameAndDescription)) - .applyTemplateOnPipelineElement()); + .applyTemplateOnPipelineElement()); } @POST @@ -203,25 +219,29 @@ public Response getPipelineElementForTemplate(@Parameter(description = "The id o @Consumes(MediaType.APPLICATION_JSON) @JacksonSerialized @Operation(summary = "Configure an adapter with a pipeline element template.", - tags = {"Pipeline Element Templates"}, - responses = { - @ApiResponse(content = { - @Content( - mediaType = "application/json", - schema = @Schema(implementation = AdapterDescription.class)) - }, responseCode = "200", description = "The configured adapter model"), - }) - public Response getPipelineElementForTemplate(@Parameter(description = "The id of the pipeline element template", required = true) - @PathParam("id") String id, - - @Parameter(description = "Overwrite the name and description of the pipeline element with the labels given in the pipeline element template") - @QueryParam("overwriteNames") String overwriteNameAndDescription, - - @RequestBody(description = "The adapter that should be configured with the template contents", - content = @Content(schema = @Schema(implementation = AdapterDescription.class))) AdapterDescription adapterDescription) { + tags = {"Pipeline Element Templates"}, + responses = { + @ApiResponse(content = { + @Content( + mediaType = "application/json", + schema = @Schema(implementation = AdapterDescription.class)) + }, responseCode = "200", description = "The configured adapter model"), + }) + public Response getPipelineElementForTemplate( + @Parameter(description = "The id of the pipeline element template", required = true) + @PathParam("id") String id, + + @Parameter(description = "Overwrite the name and description of the pipeline element" + + "with the labels given in the pipeline element template") + @QueryParam("overwriteNames") String overwriteNameAndDescription, + + @RequestBody(description = "The adapter that should be configured with the template contents", + content = @Content(schema = @Schema(implementation = AdapterDescription.class))) + AdapterDescription adapterDescription) { PipelineElementTemplate template = getPipelineElementTemplateStorage().getElementById(id); - var desc = new AdapterTemplateHandler(template, adapterDescription, Boolean.parseBoolean(overwriteNameAndDescription)) - .applyTemplateOnPipelineElement(); + var desc = + new AdapterTemplateHandler(template, adapterDescription, Boolean.parseBoolean(overwriteNameAndDescription)) + .applyTemplateOnPipelineElement(); return ok(desc); } } From efdd5a685082c8d25e05a5ec8eeadf88340a3806 Mon Sep 17 00:00:00 2001 From: bossenti Date: Sun, 18 Dec 2022 20:49:38 +0100 Subject: [PATCH 3/5] add checkstyle to streampipes-backend --- streampipes-backend/pom.xml | 7 +- .../StreamPipesBackendApplication.java | 82 ++++--- .../backend/StreamPipesEnvChecker.java | 23 +- .../backend/StreamPipesPasswordEncoder.java | 9 +- .../backend/StreamPipesResourceConfig.java | 224 +++++++++++------- .../backend/UnauthenticatedInterfaces.java | 42 ++-- .../backend/WebSecurityConfig.java | 31 +-- .../migrations/AvailableMigrations.java | 8 +- .../v070/CreateAssetLinkTypeMigration.java | 3 +- .../v070/CreateDefaultAssetMigration.java | 3 +- .../v070/CreateFileAssetTypeMigration.java | 12 +- .../v090/UpdateUsernameViewMigration.java | 1 + .../src/main/resources/application.properties | 1 - .../src/main/resources/openapi.yaml | 2 +- 14 files changed, 261 insertions(+), 187 deletions(-) diff --git a/streampipes-backend/pom.xml b/streampipes-backend/pom.xml index e706b879c2..1e75f4012c 100644 --- a/streampipes-backend/pom.xml +++ b/streampipes-backend/pom.xml @@ -16,7 +16,8 @@ ~ --> - + 4.0.0 org.apache.streampipes @@ -134,6 +135,10 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + streampipes-backend diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesBackendApplication.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesBackendApplication.java index 12df1231a3..a5c8ef630f 100644 --- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesBackendApplication.java +++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesBackendApplication.java @@ -34,6 +34,7 @@ import org.apache.streampipes.svcdiscovery.api.model.DefaultSpServiceGroups; import org.apache.streampipes.svcdiscovery.api.model.DefaultSpServiceTags; import org.apache.streampipes.svcdiscovery.api.model.SpServiceTag; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -43,6 +44,7 @@ import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; + import java.net.UnknownHostException; import java.util.Arrays; import java.util.HashMap; @@ -56,10 +58,10 @@ @Configuration @EnableAutoConfiguration @Import({StreamPipesResourceConfig.class, - WelcomePageController.class, - StreamPipesPasswordEncoder.class, - WebSecurityConfig.class, - SpPermissionEvaluator.class + WelcomePageController.class, + StreamPipesPasswordEncoder.class, + WebSecurityConfig.class, + SpPermissionEvaluator.class }) @ComponentScan({"org.apache.streampipes.rest.*"}) public class StreamPipesBackendApplication extends StreamPipesServiceBase { @@ -82,16 +84,18 @@ public class StreamPipesBackendApplication extends StreamPipesServiceBase { private Map failedPipelines = new HashMap<>(); public static void main(String[] args) { - StreamPipesBackendApplication application = new StreamPipesBackendApplication(); - try { - BaseNetworkingConfig networkingConfig = BaseNetworkingConfig.defaultResolution(8030); - application.startStreamPipesService(StreamPipesBackendApplication.class, - DefaultSpServiceGroups.CORE, - application.serviceId(), - networkingConfig); - } catch (UnknownHostException e) { - LOG.error("Could not auto-resolve host address - please manually provide the hostname using the SP_HOST environment variable"); - } + StreamPipesBackendApplication application = new StreamPipesBackendApplication(); + try { + BaseNetworkingConfig networkingConfig = BaseNetworkingConfig.defaultResolution(8030); + application.startStreamPipesService(StreamPipesBackendApplication.class, + DefaultSpServiceGroups.CORE, + application.serviceId(), + networkingConfig); + } catch (UnknownHostException e) { + LOG.error( + "Could not auto-resolve host address - please manually provide the hostname" + + " using the `SP_HOST` environment variable"); + } } private String serviceId() { @@ -116,9 +120,9 @@ public void init() { executorService.schedule(this::startAllPreviouslyStoppedPipelines, 5, TimeUnit.SECONDS); LOG.info("Pipeline health check will run every {} seconds", HEALTH_CHECK_INTERVAL); healthCheckExecutorService.scheduleAtFixedRate(new PipelineHealthCheck(), - HEALTH_CHECK_INTERVAL, - HEALTH_CHECK_INTERVAL, - HEALTH_CHECK_UNIT); + HEALTH_CHECK_INTERVAL, + HEALTH_CHECK_INTERVAL, + HEALTH_CHECK_UNIT); LOG.info("Extensions logs will be fetched every {} seconds", LOG_FETCH_INTERVAL); logCheckExecutorService.scheduleAtFixedRate(new ExtensionsServiceLogExecutor(), @@ -160,9 +164,9 @@ public void onExit() { LOG.info("Shutting down StreamPipes..."); LOG.info("Flagging currently running pipelines for restart..."); List pipelinesToStop = getAllPipelines() - .stream() - .filter(Pipeline::isRunning) - .collect(Collectors.toList()); + .stream() + .filter(Pipeline::isRunning) + .collect(Collectors.toList()); LOG.info("Found {} running pipelines which will be stopped...", pipelinesToStop.size()); @@ -189,9 +193,9 @@ public void onExit() { private void startAllPreviouslyStoppedPipelines() { LOG.info("Checking for orphaned pipelines..."); List orphanedPipelines = getAllPipelines() - .stream() - .filter(Pipeline::isRunning) - .collect(Collectors.toList()); + .stream() + .filter(Pipeline::isRunning) + .collect(Collectors.toList()); LOG.info("Found {} orphaned pipelines", orphanedPipelines.size()); @@ -203,10 +207,10 @@ private void startAllPreviouslyStoppedPipelines() { LOG.info("Checking for gracefully shut down pipelines to be restarted..."); List pipelinesToRestart = getAllPipelines() - .stream() - .filter(p -> !(p.isRunning())) - .filter(Pipeline::isRestartOnSystemReboot) - .collect(Collectors.toList()); + .stream() + .filter(p -> !(p.isRunning())) + .filter(Pipeline::isRestartOnSystemReboot) + .collect(Collectors.toList()); LOG.info("Found {} pipelines that we are attempting to restart...", pipelinesToRestart.size()); @@ -229,15 +233,15 @@ private void startPipeline(Pipeline pipeline, boolean restartOnReboot) { int failedAttemptCount = failedPipelines.get(pipeline.getPipelineId()); if (failedAttemptCount <= MAX_PIPELINE_START_RETRIES) { LOG.error("Pipeline {} could not be restarted - I'll try again in {} seconds ({}/{} failed attempts)", - pipeline.getName(), - WAIT_TIME_AFTER_FAILURE_IN_SECONDS, - failedAttemptCount, - MAX_PIPELINE_START_RETRIES); + pipeline.getName(), + WAIT_TIME_AFTER_FAILURE_IN_SECONDS, + failedAttemptCount, + MAX_PIPELINE_START_RETRIES); schedulePipelineStart(pipeline, restartOnReboot); } else { LOG.error("Pipeline {} could not be restarted - are all pipeline element containers running?", - status.getPipelineName()); + status.getPipelineName()); } } } @@ -254,23 +258,23 @@ private void storeFailedRestartAttempt(Pipeline pipeline) { private List getAllPipelines() { return getPipelineStorage() - .getAllPipelines(); + .getAllPipelines(); } private IPipelineStorage getPipelineStorage() { return StorageDispatcher - .INSTANCE - .getNoSqlStore() - .getPipelineStorageAPI(); + .INSTANCE + .getNoSqlStore() + .getPipelineStorageAPI(); } @Override protected List getServiceTags() { return Arrays.asList( - DefaultSpServiceTags.CORE, - DefaultSpServiceTags.CONNECT_MASTER, - DefaultSpServiceTags.STREAMPIPES_CLIENT + DefaultSpServiceTags.CORE, + DefaultSpServiceTags.CONNECT_MASTER, + DefaultSpServiceTags.STREAMPIPES_CLIENT ); } diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesEnvChecker.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesEnvChecker.java index db62d1a053..86ca92016c 100644 --- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesEnvChecker.java +++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesEnvChecker.java @@ -22,6 +22,7 @@ import org.apache.streampipes.config.backend.BackendConfig; import org.apache.streampipes.config.backend.model.JwtSigningMode; import org.apache.streampipes.config.backend.model.LocalAuthConfig; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,15 +62,21 @@ private void updateJwtSettings() { } if (!Envs.SP_JWT_SIGNING_MODE.exists()) { - LOG.info("No JWT signing mode provided (using default settings), consult the docs to learn how to provide JWT settings"); + LOG.info( + "No JWT signing mode provided (using default settings), " + + "consult the docs to learn how to provide JWT settings"); } else if (localAuthConfig.getJwtSigningMode() == JwtSigningMode.HMAC && !Envs.SP_JWT_SECRET.exists()) { - LOG.warn("JWT signing mode set to HMAC but no secret provided (falling back to auto-generated secret), provide a {} variable", - Envs.SP_JWT_SECRET.getEnvVariableName()); - } else if (localAuthConfig.getJwtSigningMode() == JwtSigningMode.RSA && - ((!Envs.SP_JWT_PUBLIC_KEY_LOC.exists() || !Envs.SP_JWT_PRIVATE_KEY_LOC.exists()) || incompleteConfig)) { - LOG.warn("JWT signing mode set to RSA but no public or private key location provided, do you provide {} and {} variables?", - Envs.SP_JWT_PRIVATE_KEY_LOC.getEnvVariableName(), - Envs.SP_JWT_PUBLIC_KEY_LOC.getEnvVariableName()); + LOG.warn( + "JWT signing mode set to HMAC but no secret provided (falling back to auto-generated secret), " + + "provide a {} variable", + Envs.SP_JWT_SECRET.getEnvVariableName()); + } else if (localAuthConfig.getJwtSigningMode() == JwtSigningMode.RSA + && ((!Envs.SP_JWT_PUBLIC_KEY_LOC.exists() || !Envs.SP_JWT_PRIVATE_KEY_LOC.exists()) || incompleteConfig)) { + LOG.warn( + "JWT signing mode set to RSA but no public or private key location provided, " + + "do you provide {} and {} variables?", + Envs.SP_JWT_PRIVATE_KEY_LOC.getEnvVariableName(), + Envs.SP_JWT_PUBLIC_KEY_LOC.getEnvVariableName()); } if (!incompleteConfig) { LOG.info("Updating local auth config with signing mode {}", localAuthConfig.getJwtSigningMode().name()); diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesPasswordEncoder.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesPasswordEncoder.java index b6e5cca0fa..ddb5fed4a1 100644 --- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesPasswordEncoder.java +++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesPasswordEncoder.java @@ -19,6 +19,7 @@ package org.apache.streampipes.backend; import org.apache.streampipes.user.management.authentication.StreamPipesCredentialsMatcher; + import org.springframework.context.annotation.Bean; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Component; @@ -26,8 +27,8 @@ @Component public class StreamPipesPasswordEncoder { - @Bean - public PasswordEncoder passwordEncoder() { - return new StreamPipesCredentialsMatcher(); - } + @Bean + public PasswordEncoder passwordEncoder() { + return new StreamPipesCredentialsMatcher(); + } } diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java index 07a98cce44..206522c85f 100644 --- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java +++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java @@ -18,11 +18,62 @@ package org.apache.streampipes.backend; -import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource; -import org.apache.streampipes.ps.*; -import org.apache.streampipes.rest.impl.*; -import org.apache.streampipes.rest.impl.admin.*; -import org.apache.streampipes.rest.impl.connect.*; +import org.apache.streampipes.ps.DataLakeImageResource; +import org.apache.streampipes.ps.DataLakeMeasureResourceV3; +import org.apache.streampipes.ps.DataLakeMeasureResourceV4; +import org.apache.streampipes.ps.DataLakeResourceV3; +import org.apache.streampipes.ps.DataLakeResourceV4; +import org.apache.streampipes.ps.PipelineElementTemplateResource; +import org.apache.streampipes.rest.impl.AccountActivationResource; +import org.apache.streampipes.rest.impl.AdapterMonitoringResource; +import org.apache.streampipes.rest.impl.AssetDashboardResource; +import org.apache.streampipes.rest.impl.AssetManagementResource; +import org.apache.streampipes.rest.impl.Authentication; +import org.apache.streampipes.rest.impl.AutoComplete; +import org.apache.streampipes.rest.impl.CategoryResource; +import org.apache.streampipes.rest.impl.ContainerProvidedOptions; +import org.apache.streampipes.rest.impl.DataStream; +import org.apache.streampipes.rest.impl.EmailResource; +import org.apache.streampipes.rest.impl.FunctionsResource; +import org.apache.streampipes.rest.impl.GenericStorageResource; +import org.apache.streampipes.rest.impl.LabelResource; +import org.apache.streampipes.rest.impl.MeasurementUnitResource; +import org.apache.streampipes.rest.impl.Notification; +import org.apache.streampipes.rest.impl.OntologyMeasurementUnit; +import org.apache.streampipes.rest.impl.PipelineCache; +import org.apache.streampipes.rest.impl.PipelineCanvasMetadataCache; +import org.apache.streampipes.rest.impl.PipelineCanvasMetadataResource; +import org.apache.streampipes.rest.impl.PipelineCategory; +import org.apache.streampipes.rest.impl.PipelineElementAsset; +import org.apache.streampipes.rest.impl.PipelineElementCategory; +import org.apache.streampipes.rest.impl.PipelineElementFile; +import org.apache.streampipes.rest.impl.PipelineElementPreview; +import org.apache.streampipes.rest.impl.PipelineElementRuntimeInfo; +import org.apache.streampipes.rest.impl.PipelineMonitoring; +import org.apache.streampipes.rest.impl.PipelineResource; +import org.apache.streampipes.rest.impl.PipelineTemplate; +import org.apache.streampipes.rest.impl.ResetResource; +import org.apache.streampipes.rest.impl.RestorePasswordResource; +import org.apache.streampipes.rest.impl.Setup; +import org.apache.streampipes.rest.impl.UserResource; +import org.apache.streampipes.rest.impl.Version; +import org.apache.streampipes.rest.impl.admin.ConsulConfig; +import org.apache.streampipes.rest.impl.admin.DataExportResource; +import org.apache.streampipes.rest.impl.admin.DataImportResource; +import org.apache.streampipes.rest.impl.admin.EmailConfigurationResource; +import org.apache.streampipes.rest.impl.admin.ExtensionsServiceEndpointResource; +import org.apache.streampipes.rest.impl.admin.GeneralConfigurationResource; +import org.apache.streampipes.rest.impl.admin.PermissionResource; +import org.apache.streampipes.rest.impl.admin.PipelineElementImport; +import org.apache.streampipes.rest.impl.admin.UserGroupResource; +import org.apache.streampipes.rest.impl.connect.AdapterResource; +import org.apache.streampipes.rest.impl.connect.DescriptionResource; +import org.apache.streampipes.rest.impl.connect.GuessResource; +import org.apache.streampipes.rest.impl.connect.RuntimeResolvableResource; +import org.apache.streampipes.rest.impl.connect.SourcesResource; +import org.apache.streampipes.rest.impl.connect.UnitResource; +import org.apache.streampipes.rest.impl.connect.WelcomePageMaster; +import org.apache.streampipes.rest.impl.connect.WorkerAdministrationResource; import org.apache.streampipes.rest.impl.dashboard.Dashboard; import org.apache.streampipes.rest.impl.dashboard.DashboardWidget; import org.apache.streampipes.rest.impl.dashboard.VisualizablePipelineResource; @@ -34,101 +85,104 @@ import org.apache.streampipes.rest.impl.pe.DataStreamResource; import org.apache.streampipes.rest.shared.serializer.JacksonSerializationProvider; import org.apache.streampipes.service.base.rest.ServiceHealthResource; + +import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource; import org.glassfish.jersey.media.multipart.MultiPartFeature; import org.glassfish.jersey.server.ResourceConfig; import org.springframework.context.annotation.Configuration; import javax.ws.rs.ApplicationPath; + import java.util.Collections; @Configuration @ApplicationPath("/api") public class StreamPipesResourceConfig extends ResourceConfig { - public StreamPipesResourceConfig() { - setProperties(Collections.singletonMap("jersey.config.server.response.setStatusOverSendError", true)); - register(AccountActivationResource.class); - register(AdapterMonitoringResource.class); - register(Authentication.class); - register(AssetDashboardResource.class); - register(AssetManagementResource.class); - register(AutoComplete.class); - register(CategoryResource.class); - register(ConsulConfig.class); - register(ContainerProvidedOptions.class); - register(DashboardWidget.class); - register(Dashboard.class); - register(DataExportResource.class); - register(DataImportResource.class); - register(DataLakeImageResource.class); - register(DataLakeResourceV3.class); - register(DataLakeMeasureResourceV3.class); - register(DataLakeMeasureResourceV4.class); - register(DataStream.class); - register(EmailConfigurationResource.class); - register(EmailResource.class); - register(ExtensionsServiceEndpointResource.class); - register(FunctionsResource.class); - register(GeneralConfigurationResource.class); - register(GenericStorageResource.class); - register(LabelResource.class); - register(MeasurementUnitResource.class); - register(Notification.class); - register(OntologyMeasurementUnit.class); - register(PermissionResource.class); - register(PersistedDataStreamResource.class); - register(PipelineCanvasMetadataCache.class); - register(PipelineCanvasMetadataResource.class); - register(PipelineCache.class); - register(PipelineCategory.class); - register(PipelineElementAsset.class); - register(PipelineElementCategory.class); - register(PipelineElementFile.class); - register(PipelineElementImport.class); - register(PipelineElementPreview.class); - register(PipelineElementRuntimeInfo.class); - register(PipelineMonitoring.class); - register(PipelineResource.class); - register(PipelineTemplate.class); - register(DataSinkResource.class); - register(DataProcessorResource.class); - register(DataStreamResource.class); - register(Setup.class); - register(ResetResource.class); - register(RestorePasswordResource.class); - register(ServiceHealthResource.class); - register(UserResource.class); - register(Version.class); - register(PipelineElementAsset.class); - register(DataLakeDashboardResource.class); - register(DataLakeWidgetResource.class); - register(DataLakeResourceV3.class); - register(PipelineElementFile.class); - register(DashboardWidget.class); - register(Dashboard.class); - register(VisualizablePipelineResource.class); - register(UserGroupResource.class); + public StreamPipesResourceConfig() { + setProperties(Collections.singletonMap("jersey.config.server.response.setStatusOverSendError", true)); + register(AccountActivationResource.class); + register(AdapterMonitoringResource.class); + register(Authentication.class); + register(AssetDashboardResource.class); + register(AssetManagementResource.class); + register(AutoComplete.class); + register(CategoryResource.class); + register(ConsulConfig.class); + register(ContainerProvidedOptions.class); + register(DashboardWidget.class); + register(Dashboard.class); + register(DataExportResource.class); + register(DataImportResource.class); + register(DataLakeImageResource.class); + register(DataLakeResourceV3.class); + register(DataLakeMeasureResourceV3.class); + register(DataLakeMeasureResourceV4.class); + register(DataStream.class); + register(EmailConfigurationResource.class); + register(EmailResource.class); + register(ExtensionsServiceEndpointResource.class); + register(FunctionsResource.class); + register(GeneralConfigurationResource.class); + register(GenericStorageResource.class); + register(LabelResource.class); + register(MeasurementUnitResource.class); + register(Notification.class); + register(OntologyMeasurementUnit.class); + register(PermissionResource.class); + register(PersistedDataStreamResource.class); + register(PipelineCanvasMetadataCache.class); + register(PipelineCanvasMetadataResource.class); + register(PipelineCache.class); + register(PipelineCategory.class); + register(PipelineElementAsset.class); + register(PipelineElementCategory.class); + register(PipelineElementFile.class); + register(PipelineElementImport.class); + register(PipelineElementPreview.class); + register(PipelineElementRuntimeInfo.class); + register(PipelineMonitoring.class); + register(PipelineResource.class); + register(PipelineTemplate.class); + register(DataSinkResource.class); + register(DataProcessorResource.class); + register(DataStreamResource.class); + register(Setup.class); + register(ResetResource.class); + register(RestorePasswordResource.class); + register(ServiceHealthResource.class); + register(UserResource.class); + register(Version.class); + register(PipelineElementAsset.class); + register(DataLakeDashboardResource.class); + register(DataLakeWidgetResource.class); + register(DataLakeResourceV3.class); + register(PipelineElementFile.class); + register(DashboardWidget.class); + register(Dashboard.class); + register(VisualizablePipelineResource.class); + register(UserGroupResource.class); - // Serializers - register(JacksonSerializationProvider.class); - register(MultiPartFeature.class); + // Serializers + register(JacksonSerializationProvider.class); + register(MultiPartFeature.class); - // Platform Services - register(PipelineElementTemplateResource.class); - register(DataLakeResourceV4.class); - register(OpenApiResource.class); + // Platform Services + register(PipelineElementTemplateResource.class); + register(DataLakeResourceV4.class); + register(OpenApiResource.class); - // Connect Master - register(WelcomePageMaster.class); - register(AdapterResource.class); - register(DescriptionResource.class); - register(SourcesResource.class); - register(GuessResource.class); + // Connect Master + register(WelcomePageMaster.class); + register(AdapterResource.class); + register(DescriptionResource.class); + register(SourcesResource.class); + register(GuessResource.class); // register(MultiPartFeature.class); - register(UnitResource.class); - register(WorkerAdministrationResource.class); - register(RuntimeResolvableResource.class); - } + register(UnitResource.class); + register(WorkerAdministrationResource.class); + register(RuntimeResolvableResource.class); + } } diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/UnauthenticatedInterfaces.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/UnauthenticatedInterfaces.java index 1b1ec8013e..91f703956e 100644 --- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/UnauthenticatedInterfaces.java +++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/UnauthenticatedInterfaces.java @@ -24,26 +24,26 @@ public class UnauthenticatedInterfaces { public static Collection get() { return Arrays.asList( - "/api/svchealth/*", - "/api/v2/setup/configured", - "/api/v2/auth/login", - "/api/v2/auth/register", - "/api/v2/auth/settings", - "/api/v2/auth/restore/*", - "/api/v2/asset-dashboards/images/*", - "/api/v2/restore-password/*", - "/api/v2/activate-account/*", - "/api/v2/pe/*/assets/icon", - "/api/v2/pe/*/assets/icon.png", - "/api/v2/connect/master/description/*/assets/icon", - "/api/openapi.json", - "/api/auth/**", - "/oauth2/**", - "/api/all", - "/error", - "/", - "/streampipes-backend/", - "/streampipes-backend/index.html" - ); + "/api/svchealth/*", + "/api/v2/setup/configured", + "/api/v2/auth/login", + "/api/v2/auth/register", + "/api/v2/auth/settings", + "/api/v2/auth/restore/*", + "/api/v2/asset-dashboards/images/*", + "/api/v2/restore-password/*", + "/api/v2/activate-account/*", + "/api/v2/pe/*/assets/icon", + "/api/v2/pe/*/assets/icon.png", + "/api/v2/connect/master/description/*/assets/icon", + "/api/openapi.json", + "/api/auth/**", + "/oauth2/**", + "/api/all", + "/error", + "/", + "/streampipes-backend/", + "/streampipes-backend/index.html" + ); } } diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/WebSecurityConfig.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/WebSecurityConfig.java index b33d9b07e7..0f06e065fd 100644 --- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/WebSecurityConfig.java +++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/WebSecurityConfig.java @@ -21,6 +21,7 @@ import org.apache.streampipes.rest.filter.TokenAuthenticationFilter; import org.apache.streampipes.service.base.security.UnauthorizedRequestEntryPoint; import org.apache.streampipes.user.management.service.SpUserDetailsService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -57,21 +58,21 @@ public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception protected void configure(HttpSecurity http) throws Exception { http - .cors() - .and() - .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .csrf().disable() - .formLogin().disable() - .httpBasic().disable() - .exceptionHandling() - .authenticationEntryPoint(new UnauthorizedRequestEntryPoint()) - .and() - .authorizeRequests() - .antMatchers(UnauthenticatedInterfaces.get().toArray(new String[0])).permitAll() - .anyRequest() - .authenticated().and() - .addFilterBefore(tokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); + .cors() + .and() + .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) + .and() + .csrf().disable() + .formLogin().disable() + .httpBasic().disable() + .exceptionHandling() + .authenticationEntryPoint(new UnauthorizedRequestEntryPoint()) + .and() + .authorizeRequests() + .antMatchers(UnauthenticatedInterfaces.get().toArray(new String[0])).permitAll() + .anyRequest() + .authenticated().and() + .addFilterBefore(tokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); } public TokenAuthenticationFilter tokenAuthenticationFilter() { diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/AvailableMigrations.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/AvailableMigrations.java index 8d8a8b0857..b424bba92b 100644 --- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/AvailableMigrations.java +++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/AvailableMigrations.java @@ -31,10 +31,10 @@ public class AvailableMigrations { public List getAvailableMigrations() { return Arrays.asList( - new CreateAssetLinkTypeMigration(), - new CreateDefaultAssetMigration(), - new CreateFileAssetTypeMigration(), - new UpdateUsernameViewMigration() + new CreateAssetLinkTypeMigration(), + new CreateDefaultAssetMigration(), + new CreateFileAssetTypeMigration(), + new UpdateUsernameViewMigration() ); } } diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateAssetLinkTypeMigration.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateAssetLinkTypeMigration.java index 27463d9808..9ba03f91fb 100644 --- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateAssetLinkTypeMigration.java +++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateAssetLinkTypeMigration.java @@ -31,7 +31,8 @@ public class CreateAssetLinkTypeMigration implements Migration { @Override public boolean shouldExecute() { try { - return StorageDispatcher.INSTANCE.getNoSqlStore().getGenericStorage().findAll(GenericDocTypes.DOC_ASSET_LINK_TYPE).size() == 0; + return StorageDispatcher.INSTANCE.getNoSqlStore().getGenericStorage().findAll(GenericDocTypes.DOC_ASSET_LINK_TYPE) + .size() == 0; } catch (IOException e) { return true; } diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateDefaultAssetMigration.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateDefaultAssetMigration.java index 7cf10d5c3d..2bfbb41509 100644 --- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateDefaultAssetMigration.java +++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateDefaultAssetMigration.java @@ -31,7 +31,8 @@ public class CreateDefaultAssetMigration implements Migration { @Override public boolean shouldExecute() { try { - return StorageDispatcher.INSTANCE.getNoSqlStore().getGenericStorage().findOne(GenericDocTypes.DEFAULT_ASSET_DOC_ID) == null; + return StorageDispatcher.INSTANCE.getNoSqlStore().getGenericStorage() + .findOne(GenericDocTypes.DEFAULT_ASSET_DOC_ID) == null; } catch (IOException e) { return true; } diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateFileAssetTypeMigration.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateFileAssetTypeMigration.java index 56d837be57..4370a82341 100644 --- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateFileAssetTypeMigration.java +++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateFileAssetTypeMigration.java @@ -33,12 +33,12 @@ public class CreateFileAssetTypeMigration implements Migration { public boolean shouldExecute() { try { return StorageDispatcher - .INSTANCE - .getNoSqlStore() - .getGenericStorage() - .findAll(GenericDocTypes.DOC_ASSET_LINK_TYPE) - .stream() - .noneMatch(al -> al.get("linkType").equals("file")); + .INSTANCE + .getNoSqlStore() + .getGenericStorage() + .findAll(GenericDocTypes.DOC_ASSET_LINK_TYPE) + .stream() + .noneMatch(al -> al.get("linkType").equals("file")); } catch (IOException e) { return true; } diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v090/UpdateUsernameViewMigration.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v090/UpdateUsernameViewMigration.java index 3e6c6bf5cd..691dfe679b 100644 --- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v090/UpdateUsernameViewMigration.java +++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v090/UpdateUsernameViewMigration.java @@ -21,6 +21,7 @@ import org.apache.streampipes.backend.migrations.Migration; import org.apache.streampipes.manager.setup.design.UserDesignDocument; import org.apache.streampipes.storage.couchdb.utils.Utils; + import org.lightcouch.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/streampipes-backend/src/main/resources/application.properties b/streampipes-backend/src/main/resources/application.properties index 45e100562c..1bd59f9389 100644 --- a/streampipes-backend/src/main/resources/application.properties +++ b/streampipes-backend/src/main/resources/application.properties @@ -15,7 +15,6 @@ # limitations under the License. # # - server.port=8030 server.servlet.context-path=/streampipes-backend server.tomcat.additional-tld-skip-patterns=*.jar diff --git a/streampipes-backend/src/main/resources/openapi.yaml b/streampipes-backend/src/main/resources/openapi.yaml index ef4c725f6c..ce7751e1a2 100644 --- a/streampipes-backend/src/main/resources/openapi.yaml +++ b/streampipes-backend/src/main/resources/openapi.yaml @@ -32,4 +32,4 @@ openAPI: minimum: 0 description: The username (currently the email address of the logged in user) security: - - bearerAuth: [] + - bearerAuth: [ ] From 1d2a63848564ff299bc787d8dd44e90157c0e4e5 Mon Sep 17 00:00:00 2001 From: bossenti Date: Sun, 18 Dec 2022 20:59:05 +0100 Subject: [PATCH 4/5] add checkstyle to streampipes-client --- streampipes-client/pom.xml | 12 ++- .../streampipes/client/StreamPipesClient.java | 77 ++++++++++++------- .../client/StreamPipesCredentials.java | 9 +-- .../client/annotation/NotYetImplemented.java | 4 +- .../client/api/AbstractClientApi.java | 32 ++++---- .../streampipes/client/api/AdminApi.java | 8 +- .../streampipes/client/api/CRUDApi.java | 12 +-- .../client/api/DataLakeMeasureApi.java | 3 +- .../client/api/DataProcessorApi.java | 35 +++++---- .../streampipes/client/api/DataSinkApi.java | 25 +++--- .../streampipes/client/api/DataStreamApi.java | 14 ++-- .../streampipes/client/api/FileApi.java | 44 +++++------ .../client/api/NotificationsApi.java | 2 +- .../streampipes/client/api/PipelineApi.java | 10 ++- .../api/PipelineElementTemplateApi.java | 4 +- .../StreamPipesApiKeyCredentials.java | 9 ++- .../StreamPipesTokenCredentials.java | 3 +- .../client/http/BinaryGetRequest.java | 36 +++++---- .../client/http/DeleteRequest.java | 31 ++++---- .../streampipes/client/http/GetRequest.java | 21 ++--- .../streampipes/client/http/HttpRequest.java | 36 +++++---- .../streampipes/client/http/PostRequest.java | 23 +++--- .../http/PostRequestWithPayloadResponse.java | 19 ++--- .../PostRequestWithoutPayloadResponse.java | 15 ++-- .../streampipes/client/http/PutRequest.java | 19 ++--- .../client/http/header/Headers.java | 8 +- .../streampipes/client/live/KafkaConfig.java | 8 +- .../client/live/SubscriptionManager.java | 30 ++++---- .../model/ClientConnectionConfigResolver.java | 4 +- .../client/model/StreamPipesClientConfig.java | 3 +- .../streampipes/client/paths/ApiPath.java | 3 +- .../client/serializer/ListSerializer.java | 9 ++- .../client/serializer/ObjectSerializer.java | 7 +- .../client/serializer/Serializer.java | 11 +-- .../client/util/StreamPipesApiPath.java | 16 ++-- 35 files changed, 348 insertions(+), 254 deletions(-) diff --git a/streampipes-client/pom.xml b/streampipes-client/pom.xml index 3023ecb36a..7db3fee9f2 100644 --- a/streampipes-client/pom.xml +++ b/streampipes-client/pom.xml @@ -17,7 +17,8 @@ ~ --> - + streampipes-parent org.apache.streampipes @@ -85,4 +86,13 @@ + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + + diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/StreamPipesClient.java b/streampipes-client/src/main/java/org/apache/streampipes/client/StreamPipesClient.java index e8506a3263..e7546c4912 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/StreamPipesClient.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/StreamPipesClient.java @@ -17,7 +17,21 @@ */ package org.apache.streampipes.client; -import org.apache.streampipes.client.api.*; +import org.apache.streampipes.client.api.AdminApi; +import org.apache.streampipes.client.api.CustomRequestApi; +import org.apache.streampipes.client.api.DataLakeMeasureApi; +import org.apache.streampipes.client.api.DataProcessorApi; +import org.apache.streampipes.client.api.DataSinkApi; +import org.apache.streampipes.client.api.DataStreamApi; +import org.apache.streampipes.client.api.FileApi; +import org.apache.streampipes.client.api.NotificationsApi; +import org.apache.streampipes.client.api.PipelineApi; +import org.apache.streampipes.client.api.PipelineElementTemplateApi; +import org.apache.streampipes.client.api.SupportsDataProcessorApi; +import org.apache.streampipes.client.api.SupportsDataSinkApi; +import org.apache.streampipes.client.api.SupportsDataStreamApi; +import org.apache.streampipes.client.api.SupportsPipelineApi; +import org.apache.streampipes.client.api.SupportsPipelineElementTemplateApi; import org.apache.streampipes.client.credentials.CredentialsProvider; import org.apache.streampipes.client.model.ClientConnectionUrlResolver; import org.apache.streampipes.client.model.StreamPipesClientConfig; @@ -32,18 +46,33 @@ import java.io.Serializable; public class StreamPipesClient implements SupportsPipelineApi, - SupportsPipelineElementTemplateApi, - SupportsDataSinkApi, - SupportsDataStreamApi, - SupportsDataProcessorApi, - Serializable { + SupportsPipelineElementTemplateApi, + SupportsDataSinkApi, + SupportsDataStreamApi, + SupportsDataProcessorApi, + Serializable { private static final Integer SP_DEFAULT_PORT = 80; private StreamPipesClientConfig config; + private StreamPipesClient(ClientConnectionUrlResolver connectionConfig) { + this.config = new StreamPipesClientConfig(connectionConfig); + this.registerDataFormat(new JsonDataFormatFactory()); + this.registerDataFormat(new FstDataFormatFactory()); + this.registerDataFormat(new CborDataFormatFactory()); + } + + private StreamPipesClient(String streamPipesHost, + Integer streamPipesPort, + CredentialsProvider credentials, + boolean httpsDisabled) { + this(new StreamPipesClientConnectionConfig(credentials, streamPipesHost, streamPipesPort, httpsDisabled)); + } + /** * Create a new StreamPipes API client with a runtime connection resolver + * * @param connectionConfig A ClientConnectionConfigResolver providing connection details */ public static StreamPipesClient create(ClientConnectionUrlResolver connectionConfig) { @@ -52,9 +81,10 @@ public static StreamPipesClient create(ClientConnectionUrlResolver connectionCon /** * Create a new StreamPipes API client with default port and custom HTTPS settings + * * @param streamPipesHost The hostname of the StreamPipes instance without scheme - * @param credentials The credentials object - * @param httpsDisabled Set true if the instance is not served over HTTPS + * @param credentials The credentials object + * @param httpsDisabled Set true if the instance is not served over HTTPS */ public static StreamPipesClient create(String streamPipesHost, CredentialsProvider credentials, @@ -64,8 +94,9 @@ public static StreamPipesClient create(String streamPipesHost, /** * Create a new StreamPipes API client with default port 80 and HTTPS settings (HTTPS enabled) + * * @param streamPipesHost The hostname of the StreamPipes instance without scheme - * @param credentials The credentials object + * @param credentials The credentials object */ public static StreamPipesClient create(String streamPipesHost, CredentialsProvider credentials) { @@ -74,9 +105,10 @@ public static StreamPipesClient create(String streamPipesHost, /** * Create a new StreamPipes API client with custom port and default HTTPS settings + * * @param streamPipesHost The hostname of the StreamPipes instance without scheme * @param streamPipesPort The port of the StreamPipes instance - * @param credentials The credentials object + * @param credentials The credentials object */ public static StreamPipesClient create(String streamPipesHost, Integer streamPipesPort, @@ -86,10 +118,11 @@ public static StreamPipesClient create(String streamPipesHost, /** * Create a new StreamPipes API client with custom port and HTTPS settings + * * @param streamPipesHost The hostname of the StreamPipes instance without scheme * @param streamPipesPort The port of the StreamPipes instance - * @param credentials The credentials object - * @param httpsDisabled Set true if the instance is not served over HTTPS + * @param credentials The credentials object + * @param httpsDisabled Set true if the instance is not served over HTTPS */ public static StreamPipesClient create(String streamPipesHost, Integer streamPipesPort, @@ -98,22 +131,9 @@ public static StreamPipesClient create(String streamPipesHost, return new StreamPipesClient(streamPipesHost, streamPipesPort, credentials, httpsDisabled); } - private StreamPipesClient(ClientConnectionUrlResolver connectionConfig) { - this.config = new StreamPipesClientConfig(connectionConfig); - this.registerDataFormat(new JsonDataFormatFactory()); - this.registerDataFormat(new FstDataFormatFactory()); - this.registerDataFormat(new CborDataFormatFactory()); - } - - private StreamPipesClient(String streamPipesHost, - Integer streamPipesPort, - CredentialsProvider credentials, - boolean httpsDisabled) { - this(new StreamPipesClientConnectionConfig(credentials, streamPipesHost, streamPipesPort, httpsDisabled)); - } - /** * Register a new data format that is used by the live API + * * @param spDataFormatFactory The data format factory */ public void registerDataFormat(SpDataFormatFactory spDataFormatFactory) { @@ -134,6 +154,7 @@ public ClientConnectionUrlResolver getConnectionConfig() { /** * Get API to work with pipelines + * * @return {@link org.apache.streampipes.client.api.PipelineApi} */ @Override @@ -143,6 +164,7 @@ public PipelineApi pipelines() { /** * Get API to work with pipline element templates + * * @return {@link org.apache.streampipes.client.api.PipelineElementTemplateApi} */ @Override @@ -152,6 +174,7 @@ public PipelineElementTemplateApi pipelineElementTemplates() { /** * Get API to work with data sinks + * * @return {@link org.apache.streampipes.client.api.DataSinkApi} */ @Override @@ -161,6 +184,7 @@ public DataSinkApi sinks() { /** * Get API to work with data streams + * * @return {@link org.apache.streampipes.client.api.DataStreamApi} */ @Override @@ -170,6 +194,7 @@ public DataStreamApi streams() { /** * Get API to work with data processors + * * @return {@link org.apache.streampipes.client.api.DataProcessorApi} */ @Override diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/StreamPipesCredentials.java b/streampipes-client/src/main/java/org/apache/streampipes/client/StreamPipesCredentials.java index 5457494bad..ad574279f4 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/StreamPipesCredentials.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/StreamPipesCredentials.java @@ -25,8 +25,10 @@ public class StreamPipesCredentials { /** * Create new credentials settings - * @param username The username of the authenticated user - note that this is currently the email address of the registered user! - * @param apiKey The API key as generated by StreamPipes + * + * @param username The username of the authenticated user - + * note that this is currently the email address of the registered user! + * @param apiKey The API key as generated by StreamPipes */ public static CredentialsProvider withApiKey(String username, String apiKey) { @@ -39,7 +41,4 @@ public static CredentialsProvider withServiceToken(String username, } - - - } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/annotation/NotYetImplemented.java b/streampipes-client/src/main/java/org/apache/streampipes/client/annotation/NotYetImplemented.java index fdc3fd8be2..02f8bea403 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/annotation/NotYetImplemented.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/annotation/NotYetImplemented.java @@ -1,4 +1,4 @@ -package org.apache.streampipes.client.annotation;/* +/* * 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. @@ -16,5 +16,7 @@ * */ +package org.apache.streampipes.client.annotation; + public @interface NotYetImplemented { } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/api/AbstractClientApi.java b/streampipes-client/src/main/java/org/apache/streampipes/client/api/AbstractClientApi.java index 5b8fa01583..2297b5302f 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/api/AbstractClientApi.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/api/AbstractClientApi.java @@ -17,7 +17,11 @@ */ package org.apache.streampipes.client.api; -import org.apache.streampipes.client.http.*; +import org.apache.streampipes.client.http.DeleteRequest; +import org.apache.streampipes.client.http.GetRequest; +import org.apache.streampipes.client.http.PostRequestWithPayloadResponse; +import org.apache.streampipes.client.http.PostRequestWithoutPayloadResponse; +import org.apache.streampipes.client.http.PutRequest; import org.apache.streampipes.client.model.StreamPipesClientConfig; import org.apache.streampipes.client.serializer.ObjectSerializer; import org.apache.streampipes.client.serializer.Serializer; @@ -32,8 +36,8 @@ public AbstractClientApi(StreamPipesClientConfig clientConfig) { this.clientConfig = clientConfig; } - protected O post(StreamPipesApiPath apiPath, Class responseClass) { - ObjectSerializer serializer = new ObjectSerializer<>(); + protected T post(StreamPipesApiPath apiPath, Class responseClass) { + ObjectSerializer serializer = new ObjectSerializer<>(); return new PostRequestWithPayloadResponse<>(clientConfig, apiPath, serializer, responseClass).executeRequest(); } @@ -47,26 +51,26 @@ protected void put(StreamPipesApiPath apiPath, T object) { new PutRequest<>(clientConfig, apiPath, serializer, object).executeRequest(); } - protected O delete(StreamPipesApiPath apiPath, Class responseClass) { - Serializer serializer = new ObjectSerializer<>(); + protected T delete(StreamPipesApiPath apiPath, Class responseClass) { + Serializer serializer = new ObjectSerializer<>(); return new DeleteRequest<>(clientConfig, apiPath, responseClass, serializer).executeRequest(); } - protected O delete(StreamPipesApiPath apiPath, - T object, - Class responseClass) { - Serializer serializer = new ObjectSerializer<>(); + protected V delete(StreamPipesApiPath apiPath, + K object, + Class responseClass) { + Serializer serializer = new ObjectSerializer<>(); return new DeleteRequest<>(clientConfig, apiPath, responseClass, serializer, object).executeRequest(); } - protected O post(StreamPipesApiPath apiPath, T object, Class responseClass) { - ObjectSerializer serializer = new ObjectSerializer<>(); + protected V post(StreamPipesApiPath apiPath, K object, Class responseClass) { + ObjectSerializer serializer = new ObjectSerializer<>(); return new PostRequestWithPayloadResponse<>(clientConfig, apiPath, serializer, object, responseClass) - .executeRequest(); + .executeRequest(); } - protected O getSingle(StreamPipesApiPath apiPath, Class targetClass) throws SpRuntimeException { - ObjectSerializer serializer = new ObjectSerializer<>(); + protected T getSingle(StreamPipesApiPath apiPath, Class targetClass) throws SpRuntimeException { + ObjectSerializer serializer = new ObjectSerializer<>(); return new GetRequest<>(clientConfig, apiPath, targetClass, serializer).executeRequest(); } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/api/AdminApi.java b/streampipes-client/src/main/java/org/apache/streampipes/client/api/AdminApi.java index 835885a9c5..edffe416c2 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/api/AdminApi.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/api/AdminApi.java @@ -45,10 +45,10 @@ public void deregisterFunction(String functionId) { private StreamPipesApiPath getConnectPath() { return StreamPipesApiPath - .fromBaseApiPath() - .addToPath("connect") - .addToPath("master") - .addToPath("administration"); + .fromBaseApiPath() + .addToPath("connect") + .addToPath("master") + .addToPath("administration"); } private StreamPipesApiPath getFunctionsPath() { diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/api/CRUDApi.java b/streampipes-client/src/main/java/org/apache/streampipes/client/api/CRUDApi.java index 43b847209c..6cabcc09ab 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/api/CRUDApi.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/api/CRUDApi.java @@ -19,15 +19,15 @@ import java.util.List; -public interface CRUDApi { +public interface CRUDApi { - T get(ID id); + V get(K id); - List all(); + List all(); - void create(T element); + void create(V element); - void delete(ID id); + void delete(K id); - void update(T element); + void update(V element); } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataLakeMeasureApi.java b/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataLakeMeasureApi.java index 7e5a1b9f0d..d59b4898ea 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataLakeMeasureApi.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataLakeMeasureApi.java @@ -24,7 +24,8 @@ import java.util.List; -public class DataLakeMeasureApi extends AbstractTypedClientApi implements CRUDApi { +public class DataLakeMeasureApi extends AbstractTypedClientApi + implements CRUDApi { public DataLakeMeasureApi(StreamPipesClientConfig clientConfig) { super(clientConfig, DataLakeMeasure.class); diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataProcessorApi.java b/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataProcessorApi.java index cd64795f83..983dc4848d 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataProcessorApi.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataProcessorApi.java @@ -29,7 +29,8 @@ import java.util.List; -public class DataProcessorApi extends AbstractTypedClientApi implements CRUDApi{ +public class DataProcessorApi extends AbstractTypedClientApi + implements CRUDApi { public DataProcessorApi(StreamPipesClientConfig clientConfig) { super(clientConfig, DataProcessorInvocation.class); @@ -38,8 +39,8 @@ public DataProcessorApi(StreamPipesClientConfig clientConfig) { @Override protected StreamPipesApiPath getBaseResourcePath() { return StreamPipesApiPath.fromBaseApiPath() - .addToPath("sepas") - .addToPath("own"); + .addToPath("sepas") + .addToPath("own"); } @Override @@ -72,8 +73,9 @@ public void update(DataProcessorInvocation element) { /** * Subscribe to the output stream of the processor + * * @param processor The data processor to subscribe to - * @param callback The callback where events will be received + * @param callback The callback where events will be received */ public SpKafkaConsumer subscribe(DataProcessorInvocation processor, EventProcessor callback) { @@ -82,43 +84,46 @@ public SpKafkaConsumer subscribe(DataProcessorInvocation processor, /** * Subscribe to the output stream of the processor - * @param processor The data processor to subscribe to + * + * @param processor The data processor to subscribe to * @param kafkaConfig Additional kafka settings which will override the default value (see docs) - * @param callback The callback where events will be received + * @param callback The callback where events will be received */ public SpKafkaConsumer subscribe(DataProcessorInvocation processor, KafkaConfig kafkaConfig, EventProcessor callback) { return new SubscriptionManager(clientConfig, kafkaConfig, processor.getOutputStream().getEventGrounding(), callback) - .subscribe(); + .subscribe(); } /** * Subscribe to the input stream of the processor + * * @param processor The data processor to subscribe to - * @param index The index of the input stream - * @param callback The callback where events will be received + * @param index The index of the input stream + * @param callback The callback where events will be received */ public SpKafkaConsumer subscribe(DataProcessorInvocation processor, InputStreamIndex index, EventProcessor callback) { return new SubscriptionManager(clientConfig, - processor.getInputStreams().get(index.toIndex()).getEventGrounding(), callback).subscribe(); + processor.getInputStreams().get(index.toIndex()).getEventGrounding(), callback).subscribe(); } /** * Subscribe to the input stream of the sink - * @param processor The data processor to subscribe to - * @param index The index of the input stream + * + * @param processor The data processor to subscribe to + * @param index The index of the input stream * @param kafkaConfig Additional kafka settings which will override the default value (see docs) - * @param callback The callback where events will be received + * @param callback The callback where events will be received */ public SpKafkaConsumer subscribe(DataProcessorInvocation processor, InputStreamIndex index, KafkaConfig kafkaConfig, EventProcessor callback) { return new SubscriptionManager(clientConfig, kafkaConfig, - processor.getInputStreams().get(index.toIndex()).getEventGrounding(), callback) - .subscribe(); + processor.getInputStreams().get(index.toIndex()).getEventGrounding(), callback) + .subscribe(); } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataSinkApi.java b/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataSinkApi.java index 586591b498..b6a574fa0b 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataSinkApi.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataSinkApi.java @@ -28,7 +28,8 @@ import java.util.List; -public class DataSinkApi extends AbstractTypedClientApi implements CRUDApi { +public class DataSinkApi extends AbstractTypedClientApi + implements CRUDApi { public DataSinkApi(StreamPipesClientConfig clientConfig) { super(clientConfig, DataSinkInvocation.class); @@ -63,33 +64,35 @@ public void update(DataSinkInvocation element) { /** * Subscribe to the input stream of the sink - * @param sink The data sink to subscribe to + * + * @param sink The data sink to subscribe to * @param callback The callback where events will be received */ public SpKafkaConsumer subscribe(DataSinkInvocation sink, EventProcessor callback) { return new SubscriptionManager(clientConfig, - sink.getInputStreams().get(0).getEventGrounding(), callback).subscribe(); + sink.getInputStreams().get(0).getEventGrounding(), callback).subscribe(); } /** * Subscribe to the input stream of the sink - * @param sink The data sink to subscribe to + * + * @param sink The data sink to subscribe to * @param kafkaConfig Additional kafka settings which will override the default value (see docs) - * @param callback The callback where events will be received + * @param callback The callback where events will be received */ public SpKafkaConsumer subscribe(DataSinkInvocation sink, KafkaConfig kafkaConfig, EventProcessor callback) { return new SubscriptionManager(clientConfig, kafkaConfig, - sink.getInputStreams().get(0).getEventGrounding(), callback).subscribe(); + sink.getInputStreams().get(0).getEventGrounding(), callback).subscribe(); } public DataSinkInvocation getDataSinkForPipelineElement(String templateId, DataSinkInvocation pipelineElement) { StreamPipesApiPath path = StreamPipesApiPath.fromBaseApiPath() - .addToPath("pipeline-element-templates") - .addToPath(templateId) - .addToPath("sink"); + .addToPath("pipeline-element-templates") + .addToPath(templateId) + .addToPath("sink"); return post(path, pipelineElement, DataSinkInvocation.class); } @@ -97,7 +100,7 @@ public DataSinkInvocation getDataSinkForPipelineElement(String templateId, DataS @Override protected StreamPipesApiPath getBaseResourcePath() { return StreamPipesApiPath.fromBaseApiPath() - .addToPath("actions") - .addToPath("own"); + .addToPath("actions") + .addToPath("own"); } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataStreamApi.java b/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataStreamApi.java index 8bf016bd40..ddfab79421 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataStreamApi.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/api/DataStreamApi.java @@ -43,6 +43,7 @@ public SpDataStream get(String streamId) { /** * Get all available data streams + * * @return {@link org.apache.streampipes.model.SpDataStream} A list of all data streams owned by the user. */ @Override @@ -57,6 +58,7 @@ public void create(SpDataStream element) { /** * Delete a data stream + * * @param streamId The elementId of the stream */ @Override @@ -71,7 +73,8 @@ public void update(SpDataStream element) { /** * Subscribe to a data stream - * @param stream The data stream to subscribe to + * + * @param stream The data stream to subscribe to * @param callback The callback where events will be received */ public SpKafkaConsumer subscribe(SpDataStream stream, @@ -81,9 +84,10 @@ public SpKafkaConsumer subscribe(SpDataStream stream, /** * Subscribe to a data stream - * @param stream The data stream to subscribe to + * + * @param stream The data stream to subscribe to * @param kafkaConfig Additional kafka settings which will override the default value (see docs) - * @param callback The callback where events will be received + * @param callback The callback where events will be received */ public SpKafkaConsumer subscribe(SpDataStream stream, KafkaConfig kafkaConfig, @@ -94,7 +98,7 @@ public SpKafkaConsumer subscribe(SpDataStream stream, @Override protected StreamPipesApiPath getBaseResourcePath() { return StreamPipesApiPath.fromBaseApiPath() - .addToPath("streams") - .addToPath("own"); + .addToPath("streams") + .addToPath("own"); } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/api/FileApi.java b/streampipes-client/src/main/java/org/apache/streampipes/client/api/FileApi.java index 256ea1880b..e2c00a859c 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/api/FileApi.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/api/FileApi.java @@ -25,26 +25,26 @@ public class FileApi extends AbstractClientApi { - public FileApi(StreamPipesClientConfig clientConfig) { - super(clientConfig); - } - - public byte[] getFileContent(String filename) { - return new BinaryGetRequest(clientConfig, getBaseResourcePath(filename), null).executeRequest(); - } - - public String getFileContentAsString(String filename) { - return new String(getFileContent(filename)); - } - - public void writeToFile(String file, String fileLocation) { - new BinaryGetRequest(clientConfig, getBaseResourcePath(file), null) - .writeToFile(fileLocation); - } - - protected StreamPipesApiPath getBaseResourcePath(String fileName) { - return StreamPipesApiPath.fromBaseApiPath() - .addToPath("files") - .addToPath(fileName); - } + public FileApi(StreamPipesClientConfig clientConfig) { + super(clientConfig); + } + + public byte[] getFileContent(String filename) { + return new BinaryGetRequest(clientConfig, getBaseResourcePath(filename), null).executeRequest(); + } + + public String getFileContentAsString(String filename) { + return new String(getFileContent(filename)); + } + + public void writeToFile(String file, String fileLocation) { + new BinaryGetRequest(clientConfig, getBaseResourcePath(file), null) + .writeToFile(fileLocation); + } + + protected StreamPipesApiPath getBaseResourcePath(String fileName) { + return StreamPipesApiPath.fromBaseApiPath() + .addToPath("files") + .addToPath(fileName); + } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/api/NotificationsApi.java b/streampipes-client/src/main/java/org/apache/streampipes/client/api/NotificationsApi.java index 1b80f3fac2..699074f788 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/api/NotificationsApi.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/api/NotificationsApi.java @@ -31,7 +31,7 @@ public NotificationsApi(StreamPipesClientConfig clientConfig) { @Override protected StreamPipesApiPath getBaseResourcePath() { return StreamPipesApiPath.fromBaseApiPath() - .addToPath("notifications"); + .addToPath("notifications"); } public void add(Notification notification) { diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/api/PipelineApi.java b/streampipes-client/src/main/java/org/apache/streampipes/client/api/PipelineApi.java index d0761d3493..c49e2511aa 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/api/PipelineApi.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/api/PipelineApi.java @@ -38,11 +38,12 @@ public Pipeline get(String pipelineId) { /** * Receives all pipelines owned by the current user + * * @return (list) {@link org.apache.streampipes.model.pipeline.Pipeline} a list of all pipelines */ @Override public List all() { - return getAll(getBaseResourcePath().addToPath("own")); + return getAll(getBaseResourcePath().addToPath("own")); } @Override @@ -52,6 +53,7 @@ public void create(Pipeline element) { /** * Deletes the pipeline with a given id + * * @param pipelineId The id of the pipeline */ @Override @@ -66,6 +68,7 @@ public void update(Pipeline element) { /** * Starts a pipeline by given id + * * @param pipelineId The id of the pipeline * @return {@link org.apache.streampipes.model.pipeline.PipelineOperationStatus} the status message after invocation */ @@ -75,6 +78,7 @@ public PipelineOperationStatus start(String pipelineId) { /** * Starts a pipeline by given id + * * @param pipeline The pipeline * @return {@link org.apache.streampipes.model.pipeline.PipelineOperationStatus} the status message after invocation */ @@ -84,6 +88,7 @@ public PipelineOperationStatus start(Pipeline pipeline) { /** * Stops a pipeline by given id + * * @param pipeline The pipeline * @return {@link org.apache.streampipes.model.pipeline.PipelineOperationStatus} the status message after detach */ @@ -93,6 +98,7 @@ public PipelineOperationStatus stop(Pipeline pipeline) { /** * Stops a pipeline by given id + * * @param pipelineId The id of the pipeline * @return {@link org.apache.streampipes.model.pipeline.PipelineOperationStatus} the status message after detach */ @@ -103,6 +109,6 @@ public PipelineOperationStatus stop(String pipelineId) { @Override protected StreamPipesApiPath getBaseResourcePath() { return StreamPipesApiPath.fromBaseApiPath() - .addToPath("pipelines"); + .addToPath("pipelines"); } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/api/PipelineElementTemplateApi.java b/streampipes-client/src/main/java/org/apache/streampipes/client/api/PipelineElementTemplateApi.java index ce64a4568a..3038fefdde 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/api/PipelineElementTemplateApi.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/api/PipelineElementTemplateApi.java @@ -24,7 +24,7 @@ import java.util.List; public class PipelineElementTemplateApi extends AbstractTypedClientApi - implements CRUDApi { + implements CRUDApi { public PipelineElementTemplateApi(StreamPipesClientConfig clientConfig) { super(clientConfig, PipelineElementTemplate.class); @@ -58,6 +58,6 @@ public void update(PipelineElementTemplate element) { @Override protected StreamPipesApiPath getBaseResourcePath() { return StreamPipesApiPath.fromBaseApiPath() - .addToPath("pipeline-element-templates"); + .addToPath("pipeline-element-templates"); } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/credentials/StreamPipesApiKeyCredentials.java b/streampipes-client/src/main/java/org/apache/streampipes/client/credentials/StreamPipesApiKeyCredentials.java index 39b73a9cb4..9ff67bc075 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/credentials/StreamPipesApiKeyCredentials.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/credentials/StreamPipesApiKeyCredentials.java @@ -17,9 +17,10 @@ */ package org.apache.streampipes.client.credentials; -import org.apache.http.Header; import org.apache.streampipes.client.http.header.Headers; +import org.apache.http.Header; + import java.util.Arrays; import java.util.List; @@ -29,7 +30,7 @@ public class StreamPipesApiKeyCredentials implements CredentialsProvider { private final String apiKey; public StreamPipesApiKeyCredentials(String username, - String apiKey) { + String apiKey) { this.username = username; this.apiKey = apiKey; } @@ -45,8 +46,8 @@ public String getApiKey() { @Override public List
makeHeaders() { return Arrays.asList( - Headers.xApiUser(username), - Headers.xApiKey(apiKey) + Headers.xApiUser(username), + Headers.xApiKey(apiKey) ); } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/credentials/StreamPipesTokenCredentials.java b/streampipes-client/src/main/java/org/apache/streampipes/client/credentials/StreamPipesTokenCredentials.java index dd65a53df6..b099533e25 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/credentials/StreamPipesTokenCredentials.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/credentials/StreamPipesTokenCredentials.java @@ -17,10 +17,11 @@ */ package org.apache.streampipes.client.credentials; -import org.apache.http.Header; import org.apache.streampipes.client.http.header.Headers; import org.apache.streampipes.security.jwt.JwtTokenGenerator; +import org.apache.http.Header; + import java.util.Collections; import java.util.Date; import java.util.List; diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/http/BinaryGetRequest.java b/streampipes-client/src/main/java/org/apache/streampipes/client/http/BinaryGetRequest.java index 8dfb9ba1f5..e0f8a51877 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/http/BinaryGetRequest.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/http/BinaryGetRequest.java @@ -18,29 +18,31 @@ package org.apache.streampipes.client.http; -import org.apache.http.HttpEntity; -import org.apache.http.client.fluent.Request; import org.apache.streampipes.client.model.StreamPipesClientConfig; import org.apache.streampipes.client.serializer.Serializer; import org.apache.streampipes.client.util.StreamPipesApiPath; +import org.apache.http.HttpEntity; +import org.apache.http.client.fluent.Request; + import java.io.IOException; public class BinaryGetRequest extends HttpRequest { - public BinaryGetRequest(StreamPipesClientConfig clientConfig, StreamPipesApiPath apiPath, Serializer serializer) { - super(clientConfig, apiPath, serializer); - } - - @Override - protected Request makeRequest(Serializer serializer) { - return Request - .Get(makeUrl()) - .setHeaders(standardHeaders()); - } - - @Override - protected byte[] afterRequest(Serializer serializer, HttpEntity entity) throws IOException { - return entityAsByteArray(entity); - } + public BinaryGetRequest(StreamPipesClientConfig clientConfig, StreamPipesApiPath apiPath, + Serializer serializer) { + super(clientConfig, apiPath, serializer); + } + + @Override + protected Request makeRequest(Serializer serializer) { + return Request + .Get(makeUrl()) + .setHeaders(standardHeaders()); + } + + @Override + protected byte[] afterRequest(Serializer serializer, HttpEntity entity) throws IOException { + return entityAsByteArray(entity); + } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/http/DeleteRequest.java b/streampipes-client/src/main/java/org/apache/streampipes/client/http/DeleteRequest.java index d79072c2c4..5fefb723ea 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/http/DeleteRequest.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/http/DeleteRequest.java @@ -17,43 +17,44 @@ */ package org.apache.streampipes.client.http; -import org.apache.http.HttpEntity; -import org.apache.http.client.fluent.Request; -import org.apache.http.entity.ContentType; import org.apache.streampipes.client.model.StreamPipesClientConfig; import org.apache.streampipes.client.serializer.Serializer; import org.apache.streampipes.client.util.StreamPipesApiPath; +import org.apache.http.HttpEntity; +import org.apache.http.client.fluent.Request; +import org.apache.http.entity.ContentType; + import java.io.IOException; -public class DeleteRequest extends HttpRequest { +public class DeleteRequest extends HttpRequest { - private final Class responseClass; - private SO body; + private final Class responseClass; + private K body; public DeleteRequest(StreamPipesClientConfig clientConfig, StreamPipesApiPath apiPath, - Class responseClass, - Serializer serializer) { + Class responseClass, + Serializer serializer) { super(clientConfig, apiPath, serializer); this.responseClass = responseClass; } public DeleteRequest(StreamPipesClientConfig clientConfig, StreamPipesApiPath apiPath, - Class responseClass, - Serializer serializer, - SO body) { + Class responseClass, + Serializer serializer, + K body) { super(clientConfig, apiPath, serializer); this.responseClass = responseClass; this.body = body; } @Override - protected Request makeRequest(Serializer serializer) { + protected Request makeRequest(Serializer serializer) { var req = Request - .Delete(makeUrl()) - .setHeaders(standardJsonHeaders()); + .Delete(makeUrl()) + .setHeaders(standardJsonHeaders()); if (this.body != null) { req.bodyString(serializer.serialize(body), ContentType.APPLICATION_JSON); @@ -63,7 +64,7 @@ protected Request makeRequest(Serializer serializer) { } @Override - protected DT afterRequest(Serializer serializer, HttpEntity entity) throws IOException { + protected T afterRequest(Serializer serializer, HttpEntity entity) throws IOException { return serializer.deserialize(entityAsString(entity), responseClass); } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/http/GetRequest.java b/streampipes-client/src/main/java/org/apache/streampipes/client/http/GetRequest.java index fc71c6f669..c2e7f7f1b0 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/http/GetRequest.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/http/GetRequest.java @@ -17,35 +17,36 @@ */ package org.apache.streampipes.client.http; -import org.apache.http.HttpEntity; -import org.apache.http.client.fluent.Request; import org.apache.streampipes.client.model.StreamPipesClientConfig; import org.apache.streampipes.client.serializer.Serializer; import org.apache.streampipes.client.util.StreamPipesApiPath; +import org.apache.http.HttpEntity; +import org.apache.http.client.fluent.Request; + import java.io.IOException; -public class GetRequest extends HttpRequest { +public class GetRequest extends HttpRequest { - private Class targetClass; + private Class targetClass; public GetRequest(StreamPipesClientConfig clientConfig, StreamPipesApiPath apiPath, - Class targetClass, - Serializer serializer) { + Class targetClass, + Serializer serializer) { super(clientConfig, apiPath, serializer); this.targetClass = targetClass; } @Override - protected Request makeRequest(Serializer serializer) { + protected Request makeRequest(Serializer serializer) { return Request - .Get(makeUrl()) - .setHeaders(standardJsonHeaders()); + .Get(makeUrl()) + .setHeaders(standardJsonHeaders()); } @Override - protected DT afterRequest(Serializer serializer, HttpEntity entity) throws IOException { + protected V afterRequest(Serializer serializer, HttpEntity entity) throws IOException { return serializer.deserialize(entityAsString(entity), targetClass); } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/http/HttpRequest.java b/streampipes-client/src/main/java/org/apache/streampipes/client/http/HttpRequest.java index d1b902dc5f..b0ffc92ad5 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/http/HttpRequest.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/http/HttpRequest.java @@ -17,10 +17,6 @@ */ package org.apache.streampipes.client.http; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.http.*; -import org.apache.http.client.fluent.Request; -import org.apache.http.util.EntityUtils; import org.apache.streampipes.client.http.header.Headers; import org.apache.streampipes.client.model.ClientConnectionUrlResolver; import org.apache.streampipes.client.model.StreamPipesClientConfig; @@ -28,6 +24,15 @@ import org.apache.streampipes.client.util.StreamPipesApiPath; import org.apache.streampipes.commons.exceptions.SpRuntimeException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.http.Header; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.StatusLine; +import org.apache.http.client.fluent.Request; +import org.apache.http.util.EntityUtils; + import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; @@ -39,17 +44,17 @@ import java.util.Arrays; import java.util.List; -public abstract class HttpRequest { +public abstract class HttpRequest { private final StreamPipesClientConfig clientConfig; private final ClientConnectionUrlResolver connectionConfig; private final StreamPipesApiPath apiPath; private final ObjectMapper objectMapper; - private final Serializer serializer; + private final Serializer serializer; public HttpRequest(StreamPipesClientConfig clientConfig, StreamPipesApiPath apiPath, - Serializer serializer) { + Serializer serializer) { this.clientConfig = clientConfig; this.connectionConfig = clientConfig.getConnectionConfig(); this.objectMapper = clientConfig.getSerializer(); @@ -87,7 +92,7 @@ protected String makeUrl(boolean includePath) throws SpRuntimeException { return baseUrl; } - public DT executeRequest() { + public T executeRequest() { Request request = makeRequest(serializer); try { HttpResponse response = request.execute().returnResponse(); @@ -96,13 +101,15 @@ public DT executeRequest() { return afterRequest(serializer, response.getEntity()); } else { if (status.getStatusCode() == 401) { - throw new SpRuntimeException(" 401 - Access to this resource is forbidden - did you provide a poper API key or client secret?"); + throw new SpRuntimeException( + " 401 - Access to this resource is forbidden - did you provide a poper API key or client secret?"); } else { throw new SpRuntimeException(status.getStatusCode() + " - " + status.getReasonPhrase()); } } } catch (IOException | SpRuntimeException e) { - throw new SpRuntimeException("Could not connect to the StreamPipes API - please check that StreamPipes is available", e); + throw new SpRuntimeException( + "Could not connect to the StreamPipes API - please check that StreamPipes is available", e); } } @@ -119,13 +126,14 @@ public void writeToFile(String fileLocation) throws SpRuntimeException { try { URLConnection connection = url.openConnection(); - connection.setRequestProperty("Authorization", connectionConfig.getCredentials().makeHeaders().get(0).getElements()[0].getName()); + connection.setRequestProperty("Authorization", + connectionConfig.getCredentials().makeHeaders().get(0).getElements()[0].getName()); try { ReadableByteChannel readableByteChannel = Channels.newChannel(connection.getInputStream()); FileOutputStream fileOutputStream = new FileOutputStream(fileLocation); fileOutputStream.getChannel() - .transferFrom(readableByteChannel, 0, Long.MAX_VALUE); + .transferFrom(readableByteChannel, 0, Long.MAX_VALUE); } catch (IOException e) { e.printStackTrace(); } @@ -143,8 +151,8 @@ protected byte[] entityAsByteArray(HttpEntity entity) throws IOException { return EntityUtils.toByteArray(entity); } - protected abstract Request makeRequest(Serializer serializer); + protected abstract Request makeRequest(Serializer serializer); - protected abstract DT afterRequest(Serializer serializer, HttpEntity entity) throws IOException; + protected abstract T afterRequest(Serializer serializer, HttpEntity entity) throws IOException; } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/http/PostRequest.java b/streampipes-client/src/main/java/org/apache/streampipes/client/http/PostRequest.java index bf99b4c9d5..fc6de13742 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/http/PostRequest.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/http/PostRequest.java @@ -17,21 +17,22 @@ */ package org.apache.streampipes.client.http; -import org.apache.http.client.fluent.Request; -import org.apache.http.entity.ContentType; import org.apache.streampipes.client.model.StreamPipesClientConfig; import org.apache.streampipes.client.serializer.Serializer; import org.apache.streampipes.client.util.StreamPipesApiPath; -public abstract class PostRequest extends HttpRequest { +import org.apache.http.client.fluent.Request; +import org.apache.http.entity.ContentType; + +public abstract class PostRequest extends HttpRequest { - private SO body; + private K body; private boolean withBody; public PostRequest(StreamPipesClientConfig clientConfig, StreamPipesApiPath apiPath, - Serializer serializer, - SO body) { + Serializer serializer, + K body) { super(clientConfig, apiPath, serializer); this.body = body; this.withBody = true; @@ -39,16 +40,16 @@ public PostRequest(StreamPipesClientConfig clientConfig, public PostRequest(StreamPipesClientConfig clientConfig, StreamPipesApiPath apiPath, - Serializer serializer) { + Serializer serializer) { super(clientConfig, apiPath, serializer); this.withBody = false; } @Override - protected Request makeRequest(Serializer serializer) { + protected Request makeRequest(Serializer serializer) { Request request = Request - .Post(makeUrl()) - .setHeaders(standardPostHeaders()); + .Post(makeUrl()) + .setHeaders(standardPostHeaders()); if (withBody) { addBody(request, serializer); @@ -57,7 +58,7 @@ protected Request makeRequest(Serializer serializer) { return request; } - protected void addBody(Request request, Serializer serializer) { + protected void addBody(Request request, Serializer serializer) { request.bodyString(serializer.serialize(body), ContentType.APPLICATION_JSON); } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/http/PostRequestWithPayloadResponse.java b/streampipes-client/src/main/java/org/apache/streampipes/client/http/PostRequestWithPayloadResponse.java index e5019e368b..1b3bb11256 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/http/PostRequestWithPayloadResponse.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/http/PostRequestWithPayloadResponse.java @@ -17,36 +17,37 @@ */ package org.apache.streampipes.client.http; -import org.apache.http.HttpEntity; import org.apache.streampipes.client.model.StreamPipesClientConfig; import org.apache.streampipes.client.serializer.Serializer; import org.apache.streampipes.client.util.StreamPipesApiPath; +import org.apache.http.HttpEntity; + import java.io.IOException; -public class PostRequestWithPayloadResponse extends PostRequest { +public class PostRequestWithPayloadResponse extends PostRequest { - private Class responseClass; + private Class responseClass; public PostRequestWithPayloadResponse(StreamPipesClientConfig clientConfig, StreamPipesApiPath apiPath, - Serializer serializer, - SO body, - Class responseClass) { + Serializer serializer, + K body, + Class responseClass) { super(clientConfig, apiPath, serializer, body); this.responseClass = responseClass; } public PostRequestWithPayloadResponse(StreamPipesClientConfig clientConfig, StreamPipesApiPath apiPath, - Serializer serializer, - Class responseClass) { + Serializer serializer, + Class responseClass) { super(clientConfig, apiPath, serializer); this.responseClass = responseClass; } @Override - protected DT afterRequest(Serializer serializer, HttpEntity entity) throws IOException { + protected T afterRequest(Serializer serializer, HttpEntity entity) throws IOException { return serializer.deserialize(entityAsString(entity), responseClass); } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/http/PostRequestWithoutPayloadResponse.java b/streampipes-client/src/main/java/org/apache/streampipes/client/http/PostRequestWithoutPayloadResponse.java index cf006c2d41..be51350742 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/http/PostRequestWithoutPayloadResponse.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/http/PostRequestWithoutPayloadResponse.java @@ -17,31 +17,32 @@ */ package org.apache.streampipes.client.http; -import org.apache.http.HttpEntity; import org.apache.streampipes.client.model.StreamPipesClientConfig; import org.apache.streampipes.client.serializer.Serializer; import org.apache.streampipes.client.util.StreamPipesApiPath; +import org.apache.http.HttpEntity; + import java.io.IOException; -public class PostRequestWithoutPayloadResponse extends PostRequest { +public class PostRequestWithoutPayloadResponse extends PostRequest { public PostRequestWithoutPayloadResponse(StreamPipesClientConfig clientConfig, StreamPipesApiPath apiPath, - Serializer serializer, - SO body) { + Serializer serializer, + K body) { super(clientConfig, apiPath, serializer, body); } public PostRequestWithoutPayloadResponse(StreamPipesClientConfig clientConfig, - StreamPipesApiPath apiPath, - Serializer serializer) { + StreamPipesApiPath apiPath, + Serializer serializer) { super(clientConfig, apiPath, serializer); } @Override - protected Void afterRequest(Serializer serializer, HttpEntity entity) throws IOException { + protected Void afterRequest(Serializer serializer, HttpEntity entity) throws IOException { return null; } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/http/PutRequest.java b/streampipes-client/src/main/java/org/apache/streampipes/client/http/PutRequest.java index cf36cf131d..3abbed6ae2 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/http/PutRequest.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/http/PutRequest.java @@ -18,29 +18,30 @@ package org.apache.streampipes.client.http; -import org.apache.http.HttpEntity; -import org.apache.http.client.fluent.Request; -import org.apache.http.entity.ContentType; import org.apache.streampipes.client.model.StreamPipesClientConfig; import org.apache.streampipes.client.serializer.Serializer; import org.apache.streampipes.client.util.StreamPipesApiPath; +import org.apache.http.HttpEntity; +import org.apache.http.client.fluent.Request; +import org.apache.http.entity.ContentType; + import java.io.IOException; -public class PutRequest extends HttpRequest { +public class PutRequest extends HttpRequest { - private final SO body; + private final T body; public PutRequest(StreamPipesClientConfig clientConfig, StreamPipesApiPath apiPath, - Serializer serializer, - SO body) { + Serializer serializer, + T body) { super(clientConfig, apiPath, serializer); this.body = body; } @Override - protected Request makeRequest(Serializer serializer) { + protected Request makeRequest(Serializer serializer) { Request request = Request .Put(makeUrl()) .setHeaders(standardPostHeaders()); @@ -51,7 +52,7 @@ protected Request makeRequest(Serializer serializer) { } @Override - protected Void afterRequest(Serializer serializer, HttpEntity entity) throws IOException { + protected Void afterRequest(Serializer serializer, HttpEntity entity) throws IOException { return null; } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/http/header/Headers.java b/streampipes-client/src/main/java/org/apache/streampipes/client/http/header/Headers.java index 15997705af..0d902e7aed 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/http/header/Headers.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/http/header/Headers.java @@ -20,7 +20,13 @@ import org.apache.http.Header; import org.apache.http.message.BasicHeader; -import static org.apache.streampipes.commons.constants.HttpConstants.*; +import static org.apache.streampipes.commons.constants.HttpConstants.ACCEPT; +import static org.apache.streampipes.commons.constants.HttpConstants.APPLICATION_JSON_TYPE; +import static org.apache.streampipes.commons.constants.HttpConstants.AUTHORIZATION; +import static org.apache.streampipes.commons.constants.HttpConstants.BEARER; +import static org.apache.streampipes.commons.constants.HttpConstants.CONTENT_TYPE; +import static org.apache.streampipes.commons.constants.HttpConstants.X_API_KEY; +import static org.apache.streampipes.commons.constants.HttpConstants.X_API_USER; public class Headers { diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/live/KafkaConfig.java b/streampipes-client/src/main/java/org/apache/streampipes/client/live/KafkaConfig.java index 045e3e4e2b..1eae706246 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/live/KafkaConfig.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/live/KafkaConfig.java @@ -22,15 +22,15 @@ public class KafkaConfig { private String kafkaHost; private Integer kafkaPort; - public static KafkaConfig create(String kafkaHost, Integer kafkaPort) { - return new KafkaConfig(kafkaHost, kafkaPort); - } - private KafkaConfig(String kafkaHost, Integer kafkaPort) { this.kafkaHost = kafkaHost; this.kafkaPort = kafkaPort; } + public static KafkaConfig create(String kafkaHost, Integer kafkaPort) { + return new KafkaConfig(kafkaHost, kafkaPort); + } + public String getKafkaHost() { return kafkaHost; } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/live/SubscriptionManager.java b/streampipes-client/src/main/java/org/apache/streampipes/client/live/SubscriptionManager.java index 2d93f77059..673fb0b453 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/live/SubscriptionManager.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/live/SubscriptionManager.java @@ -57,21 +57,22 @@ public SubscriptionManager(StreamPipesClientConfig clientConfig, public SpKafkaConsumer subscribe() { Optional formatConverterOpt = this - .clientConfig - .getRegisteredDataFormats() + .clientConfig + .getRegisteredDataFormats() + .stream() + .filter(format -> this.grounding + .getTransportFormats() + .get(0) + .getRdfType() .stream() - .filter(format -> this.grounding - .getTransportFormats() - .get(0) - .getRdfType() - .stream() - .anyMatch(tf -> tf.toString().equals(format.getTransportFormatRdfUri()))) - .findFirst(); + .anyMatch(tf -> tf.toString().equals(format.getTransportFormatRdfUri()))) + .findFirst(); if (formatConverterOpt.isPresent()) { final SpDataFormatDefinition converter = formatConverterOpt.get().createInstance(); - KafkaTransportProtocol protocol = overrideKafkaSettings ? overrideHostname(getKafkaProtocol()) : getKafkaProtocol(); + KafkaTransportProtocol protocol = + overrideKafkaSettings ? overrideHostname(getKafkaProtocol()) : getKafkaProtocol(); SpKafkaConsumer kafkaConsumer = new SpKafkaConsumer(protocol, getOutputTopic(), event -> { try { Event spEvent = EventFactory.fromMap(converter.toMap(event)); @@ -84,7 +85,8 @@ public SpKafkaConsumer subscribe() { t.start(); return kafkaConsumer; } else { - throw new SpRuntimeException("No converter found for data format - did you add a format factory (client.registerDataFormat)?"); + throw new SpRuntimeException( + "No converter found for data format - did you add a format factory (client.registerDataFormat)?"); } } @@ -100,8 +102,8 @@ private KafkaTransportProtocol getKafkaProtocol() { private String getOutputTopic() { return this.grounding - .getTransportProtocol() - .getTopicDefinition() - .getActualTopicName(); + .getTransportProtocol() + .getTopicDefinition() + .getActualTopicName(); } } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/model/ClientConnectionConfigResolver.java b/streampipes-client/src/main/java/org/apache/streampipes/client/model/ClientConnectionConfigResolver.java index e28bbb7520..20fdf130ad 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/model/ClientConnectionConfigResolver.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/model/ClientConnectionConfigResolver.java @@ -31,8 +31,8 @@ default String getBaseUrl() { StringJoiner joiner = new StringJoiner(""); String protocol = isHttpsDisabled() ? "http://" : "https://"; joiner.add(protocol + getStreamPipesHost() - + ":" - + getStreamPipesPort()); + + ":" + + getStreamPipesPort()); return joiner.toString(); } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/model/StreamPipesClientConfig.java b/streampipes-client/src/main/java/org/apache/streampipes/client/model/StreamPipesClientConfig.java index ce117c0d70..c2290dd467 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/model/StreamPipesClientConfig.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/model/StreamPipesClientConfig.java @@ -17,10 +17,11 @@ */ package org.apache.streampipes.client.model; -import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.streampipes.dataformat.SpDataFormatFactory; import org.apache.streampipes.serializers.json.JacksonSerializer; +import com.fasterxml.jackson.databind.ObjectMapper; + import java.util.ArrayList; import java.util.List; diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/paths/ApiPath.java b/streampipes-client/src/main/java/org/apache/streampipes/client/paths/ApiPath.java index fa1f82afa4..8cf7033cf2 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/paths/ApiPath.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/paths/ApiPath.java @@ -19,5 +19,6 @@ public class ApiPath { - public static String EMAIL_RESOURCE = "api/v2/mail"; + public static final String EMAIL_RESOURCE = "api/v2/mail"; } + diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/serializer/ListSerializer.java b/streampipes-client/src/main/java/org/apache/streampipes/client/serializer/ListSerializer.java index 30066dcbe2..f7d7b89c86 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/serializer/ListSerializer.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/serializer/ListSerializer.java @@ -17,18 +17,19 @@ */ package org.apache.streampipes.client.serializer; +import org.apache.streampipes.commons.exceptions.SpRuntimeException; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.type.CollectionType; -import org.apache.streampipes.commons.exceptions.SpRuntimeException; import java.util.List; -public class ListSerializer extends Serializer> { +public class ListSerializer extends Serializer> { @Override - public List deserialize(String response, Class targetClass) { + public List deserialize(String response, Class targetClass) { CollectionType listType = objectMapper.getTypeFactory() - .constructCollectionType(List.class, targetClass); + .constructCollectionType(List.class, targetClass); try { return objectMapper.readValue(response, listType); } catch (JsonProcessingException e) { diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/serializer/ObjectSerializer.java b/streampipes-client/src/main/java/org/apache/streampipes/client/serializer/ObjectSerializer.java index 0774039967..5e1e99e5af 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/serializer/ObjectSerializer.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/serializer/ObjectSerializer.java @@ -17,13 +17,14 @@ */ package org.apache.streampipes.client.serializer; -import com.fasterxml.jackson.core.JsonProcessingException; import org.apache.streampipes.commons.exceptions.SpRuntimeException; -public class ObjectSerializer extends Serializer { +import com.fasterxml.jackson.core.JsonProcessingException; + +public class ObjectSerializer extends Serializer { @Override - public DSO deserialize(String response, Class targetClass) { + public V deserialize(String response, Class targetClass) { try { return objectMapper.readValue(response, targetClass); } catch (JsonProcessingException e) { diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/serializer/Serializer.java b/streampipes-client/src/main/java/org/apache/streampipes/client/serializer/Serializer.java index c9e94be12e..435d76a59b 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/serializer/Serializer.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/serializer/Serializer.java @@ -17,12 +17,13 @@ */ package org.apache.streampipes.client.serializer; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.streampipes.commons.exceptions.SpRuntimeException; import org.apache.streampipes.serializers.json.JacksonSerializer; -public abstract class Serializer { +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public abstract class Serializer { protected ObjectMapper objectMapper; @@ -30,7 +31,7 @@ public Serializer() { this.objectMapper = JacksonSerializer.getObjectMapper(); } - public String serialize(SO object) { + public String serialize(K object) { try { return objectMapper.writeValueAsString(object); } catch (JsonProcessingException e) { @@ -38,5 +39,5 @@ public String serialize(SO object) { } } - public abstract DT deserialize(String response, Class targetClass); + public abstract T deserialize(String response, Class targetClass); } diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/util/StreamPipesApiPath.java b/streampipes-client/src/main/java/org/apache/streampipes/client/util/StreamPipesApiPath.java index 3b0534543a..f083217e11 100644 --- a/streampipes-client/src/main/java/org/apache/streampipes/client/util/StreamPipesApiPath.java +++ b/streampipes-client/src/main/java/org/apache/streampipes/client/util/StreamPipesApiPath.java @@ -17,12 +17,20 @@ */ package org.apache.streampipes.client.util; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.StringJoiner; public class StreamPipesApiPath { - private List pathItems; private static final List BaseApiPathV2 = Arrays.asList("streampipes-backend", "api", "v2"); + private List pathItems; + + private StreamPipesApiPath(List initialPathItems) { + this.pathItems = initialPathItems; + } public static StreamPipesApiPath fromStreamPipesBasePath() { List path = new ArrayList<>(Collections.singletonList("streampipes-backend")); @@ -38,10 +46,6 @@ public static StreamPipesApiPath fromStreamPipesBasePath(String allSubPaths) { return fromStreamPipesBasePath().addToPath(allSubPaths); } - private StreamPipesApiPath(List initialPathItems) { - this.pathItems = initialPathItems; - } - public StreamPipesApiPath addToPath(String pathItem) { this.pathItems.add(pathItem); return this; From b8ccc1d75e7ea21c1288b06929ec1757ac874a19 Mon Sep 17 00:00:00 2001 From: bossenti Date: Wed, 21 Dec 2022 19:53:02 +0100 Subject: [PATCH 5/5] fix checkstyle issue --- .../container/master/management/UnitMasterManagementTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagementTest.java b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagementTest.java index 2983be12a3..98fed131bd 100644 --- a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagementTest.java +++ b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagementTest.java @@ -48,7 +48,7 @@ public class UnitMasterManagementTest { @Test(expected = AdapterException.class) - public void URLisNull() throws AdapterException { + public void urlIsNull() throws AdapterException { UnitMasterManagement unitMasterManagement = new UnitMasterManagement(); unitMasterManagement.getFittingUnits(getUnitDescription("", null)); }