Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable checkstyle for streampipes-rest (#820) #825

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.streampipes.rest.impl.datalake.DataLakeDashboardResource;
import org.apache.streampipes.rest.impl.datalake.DataLakeWidgetResource;
import org.apache.streampipes.rest.impl.datalake.PersistedDataStreamResource;
import org.apache.streampipes.rest.impl.nouser.PipelineElementImportNoUser;
import org.apache.streampipes.rest.impl.pe.DataProcessorResource;
import org.apache.streampipes.rest.impl.pe.DataSinkResource;
import org.apache.streampipes.rest.impl.pe.DataStreamResource;
Expand Down Expand Up @@ -85,7 +84,6 @@ public StreamPipesResourceConfig() {
register(PipelineElementAsset.class);
register(PipelineElementCategory.class);
register(PipelineElementFile.class);
register(PipelineElementImportNoUser.class);
register(PipelineElementImport.class);
register(PipelineElementPreview.class);
register(PipelineElementRuntimeInfo.class);
Expand Down
22 changes: 22 additions & 0 deletions streampipes-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,26 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<logViolationsToConsole>true</logViolationsToConsole>
<failOnViolation>true</failOnViolation>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,106 +25,111 @@
import org.apache.streampipes.manager.pipeline.PipelineCacheManager;
import org.apache.streampipes.manager.pipeline.PipelineCanvasMetadataCacheManager;
import org.apache.streampipes.manager.pipeline.PipelineManager;
import org.apache.streampipes.resource.management.UserResourceManager;
import org.apache.streampipes.model.file.FileMetadata;
import org.apache.streampipes.model.connect.adapter.AdapterDescription;
import org.apache.streampipes.model.datalake.DataLakeMeasure;
import org.apache.streampipes.model.file.FileMetadata;
import org.apache.streampipes.model.pipeline.Pipeline;
import org.apache.streampipes.resource.management.UserResourceManager;
import org.apache.streampipes.storage.api.IDashboardStorage;
import org.apache.streampipes.storage.api.IDashboardWidgetStorage;
import org.apache.streampipes.storage.api.IDataExplorerWidgetStorage;
import org.apache.streampipes.storage.management.StorageDispatcher;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class ResetManagement {
// This class should be moved into another package. I moved it here because I got a cyclic maven
// dependency between this package and streampipes-pipeline-management
// See in issue [STREAMPIPES-405]

private static final Logger logger = LoggerFactory.getLogger(ResetManagement.class);

/**
* Remove all configurations for this user. This includes:
* [pipeline assembly cache, pipelines, adapters, files]
* @param username
*/
public static void reset(String username) {
logger.info("Start resetting the system");

// Set hide tutorial to false for user
UserResourceManager.setHideTutorial(username, true);

// Clear pipeline assembly Cache
PipelineCacheManager.removeCachedPipeline(username);
PipelineCanvasMetadataCacheManager.removeCanvasMetadataFromCache(username);

// Stop and delete all pipelines
List<Pipeline> allPipelines = PipelineManager.getAllPipelines();
allPipelines.forEach(pipeline -> {
PipelineManager.stopPipeline(pipeline.getPipelineId(), true);
PipelineManager.deletePipeline(pipeline.getPipelineId());
});

// Stop and delete all adapters
AdapterMasterManagement adapterMasterManagement = new AdapterMasterManagement();

// This class should be moved into another package. I moved it here because I got a cyclic maven
// dependency between this package and streampipes-pipeline-management
// See in issue [STREAMPIPES-405]

private static final Logger logger = LoggerFactory.getLogger(ResetManagement.class);

/**
* Remove all configurations for this user. This includes:
* [pipeline assembly cache, pipelines, adapters, files]
*
* @param username
*/
public static void reset(String username) {
logger.info("Start resetting the system");

// Set hide tutorial to false for user
UserResourceManager.setHideTutorial(username, true);

// Clear pipeline assembly Cache
PipelineCacheManager.removeCachedPipeline(username);
PipelineCanvasMetadataCacheManager.removeCanvasMetadataFromCache(username);

// Stop and delete all pipelines
List<Pipeline> allPipelines = PipelineManager.getAllPipelines();
allPipelines.forEach(pipeline -> {
PipelineManager.stopPipeline(pipeline.getPipelineId(), true);
PipelineManager.deletePipeline(pipeline.getPipelineId());
});

// Stop and delete all adapters
AdapterMasterManagement adapterMasterManagement = new AdapterMasterManagement();

try {
List<AdapterDescription> allAdapters = adapterMasterManagement.getAllAdapterInstances();
allAdapters.forEach(adapterDescription -> {
try {
List<AdapterDescription> allAdapters = adapterMasterManagement.getAllAdapterInstances();
allAdapters.forEach(adapterDescription -> {
try {
adapterMasterManagement.deleteAdapter(adapterDescription.getElementId());
} catch (AdapterException e) {
logger.error("Failed to delete adapter with id: " + adapterDescription.getElementId(), e);
}
});
adapterMasterManagement.deleteAdapter(adapterDescription.getElementId());
} catch (AdapterException e) {
logger.error("Failed to load all adapter descriptions", e);
logger.error("Failed to delete adapter with id: " + adapterDescription.getElementId(), e);
}

// Stop and delete all files
List<FileMetadata> allFiles = FileManager.getAllFiles();
allFiles.forEach(fileMetadata -> {
FileManager.deleteFile(fileMetadata.getFileId());
});

// Remove all data in data lake
DataLakeManagementV4 dataLakeManagementV4 = new DataLakeManagementV4();
List<DataLakeMeasure> allMeasurements = dataLakeManagementV4.getAllMeasurements();
allMeasurements.forEach(measurement -> {
boolean isSuccessDataLake = dataLakeManagementV4.removeMeasurement(measurement.getMeasureName());

if (isSuccessDataLake) {
dataLakeManagementV4.removeEventProperty(measurement.getMeasureName());
}
});

// Remove all data views widgets
IDataExplorerWidgetStorage widgetStorage = StorageDispatcher.INSTANCE.getNoSqlStore().getDataExplorerWidgetStorage();
widgetStorage.getAllDataExplorerWidgets().forEach(widget -> {
widgetStorage.deleteDataExplorerWidget(widget.getId());
});

// Remove all data views
IDashboardStorage dataLakeDashboardStorage = StorageDispatcher.INSTANCE.getNoSqlStore().getDataExplorerDashboardStorage();
dataLakeDashboardStorage.getAllDashboards().forEach(dashboard -> {
dataLakeDashboardStorage.deleteDashboard(dashboard.getCouchDbId());
});

// Remove all dashboard widgets
IDashboardWidgetStorage dashobardWidgetStorage = StorageDispatcher.INSTANCE.getNoSqlStore().getDashboardWidgetStorage();
dashobardWidgetStorage.getAllDashboardWidgets().forEach(widget -> {
dashobardWidgetStorage.deleteDashboardWidget(widget.getId());
});

// Remove all dashboards
IDashboardStorage dashboardStorage = StorageDispatcher.INSTANCE.getNoSqlStore().getDashboardStorage();
dashboardStorage.getAllDashboards().forEach(dashboard -> {
dashboardStorage.deleteDashboard(dashboard.getCouchDbId());
});

logger.info("Resetting the system was completed");
});
} catch (AdapterException e) {
logger.error("Failed to load all adapter descriptions", e);
}

// Stop and delete all files
List<FileMetadata> allFiles = FileManager.getAllFiles();
allFiles.forEach(fileMetadata -> {
FileManager.deleteFile(fileMetadata.getFileId());
});

// Remove all data in data lake
DataLakeManagementV4 dataLakeManagementV4 = new DataLakeManagementV4();
List<DataLakeMeasure> allMeasurements = dataLakeManagementV4.getAllMeasurements();
allMeasurements.forEach(measurement -> {
boolean isSuccessDataLake = dataLakeManagementV4.removeMeasurement(measurement.getMeasureName());

if (isSuccessDataLake) {
dataLakeManagementV4.removeEventProperty(measurement.getMeasureName());
}
});

// Remove all data views widgets
IDataExplorerWidgetStorage widgetStorage =
StorageDispatcher.INSTANCE.getNoSqlStore().getDataExplorerWidgetStorage();
widgetStorage.getAllDataExplorerWidgets().forEach(widget -> {
widgetStorage.deleteDataExplorerWidget(widget.getId());
});

// Remove all data views
IDashboardStorage dataLakeDashboardStorage =
StorageDispatcher.INSTANCE.getNoSqlStore().getDataExplorerDashboardStorage();
dataLakeDashboardStorage.getAllDashboards().forEach(dashboard -> {
dataLakeDashboardStorage.deleteDashboard(dashboard.getCouchDbId());
});

// Remove all dashboard widgets
IDashboardWidgetStorage dashobardWidgetStorage =
StorageDispatcher.INSTANCE.getNoSqlStore().getDashboardWidgetStorage();
dashobardWidgetStorage.getAllDashboardWidgets().forEach(widget -> {
dashobardWidgetStorage.deleteDashboardWidget(widget.getId());
});

// Remove all dashboards
IDashboardStorage dashboardStorage = StorageDispatcher.INSTANCE.getNoSqlStore().getDashboardStorage();
dashboardStorage.getAllDashboards().forEach(dashboard -> {
dashboardStorage.deleteDashboard(dashboard.getCouchDbId());
});

logger.info("Resetting the system was completed");
}
}

This file was deleted.

This file was deleted.

Loading