Skip to content

Commit

Permalink
Enable checkstyle for streampipes-rest (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
tenthe committed Dec 1, 2022
1 parent a981586 commit 7f2a8be
Show file tree
Hide file tree
Showing 65 changed files with 1,505 additions and 1,215 deletions.
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

0 comments on commit 7f2a8be

Please sign in to comment.