Skip to content

Commit

Permalink
feat(#3141): Add option to configure production sites (#3142)
Browse files Browse the repository at this point in the history
* feat(#3141): Add option to configure production sites

* Add headers

* Fix import

* feat: Show asset location on map

* Remove scss

* Fix formatting
  • Loading branch information
dominikriemer authored Aug 16, 2024
1 parent c15b157 commit dd8213e
Show file tree
Hide file tree
Showing 56 changed files with 1,729 additions and 156 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.streampipes.model.configuration;

import org.apache.streampipes.model.shared.annotation.TsModel;

@TsModel
public record LocationConfig(boolean locationEnabled,
String tileServerUrl,
String attributionText) {}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class SpCoreConfiguration {
private EmailConfig emailConfig;
private EmailTemplateConfig emailTemplateConfig;
private GeneralConfig generalConfig;
private LocationConfig locationConfig;

private boolean isConfigured;
private SpCoreConfigurationStatus serviceStatus;
Expand All @@ -40,6 +41,7 @@ public class SpCoreConfiguration {
private String filesDir;

public SpCoreConfiguration() {
this.locationConfig = new LocationConfig(false, "", "");
}

public String getRev() {
Expand Down Expand Up @@ -129,4 +131,12 @@ public SpCoreConfigurationStatus getServiceStatus() {
public void setServiceStatus(SpCoreConfigurationStatus serviceStatus) {
this.serviceStatus = serviceStatus;
}

public LocationConfig getLocationConfig() {
return locationConfig;
}

public void setLocationConfig(LocationConfig locationConfig) {
this.locationConfig = locationConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public static void reset(String username) {

removeAllPipelineTemplates();

clearGenericStorage();

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

Expand All @@ -106,7 +108,7 @@ private static void stopAndDeleteAllPipelines() {
private static void stopAndDeleteAllAdapters() {
AdapterMasterManagement adapterMasterManagement = new AdapterMasterManagement(
StorageDispatcher.INSTANCE.getNoSqlStore()
.getAdapterInstanceStorage(),
.getAdapterInstanceStorage(),
new SpResourceManager().manageAdapters(),
new SpResourceManager().manageDataStreams(),
AdapterMetricsManager.INSTANCE.getAdapterMetrics()
Expand Down Expand Up @@ -152,37 +154,37 @@ private static void removeAllDataInDataLake() {
private static void removeAllDataViewWidgets() {
var widgetStorage =
StorageDispatcher.INSTANCE.getNoSqlStore()
.getDataExplorerWidgetStorage();
.getDataExplorerWidgetStorage();
widgetStorage.findAll()
.forEach(widget -> widgetStorage.deleteElementById(widget.getElementId()));
.forEach(widget -> widgetStorage.deleteElementById(widget.getElementId()));
}

private static void removeAllDataViews() {
var dataLakeDashboardStorage =
StorageDispatcher.INSTANCE.getNoSqlStore()
.getDataExplorerDashboardStorage();
.getDataExplorerDashboardStorage();
dataLakeDashboardStorage.findAll()
.forEach(dashboard -> dataLakeDashboardStorage.deleteElementById(dashboard.getElementId()));
.forEach(dashboard -> dataLakeDashboardStorage.deleteElementById(dashboard.getElementId()));
}

private static void removeAllDashboardWidgets() {
var dashboardWidgetStorage =
StorageDispatcher.INSTANCE.getNoSqlStore()
.getDashboardWidgetStorage();
.getDashboardWidgetStorage();
dashboardWidgetStorage.findAll()
.forEach(widget -> dashboardWidgetStorage.deleteElementById(widget.getElementId()));
.forEach(widget -> dashboardWidgetStorage.deleteElementById(widget.getElementId()));
}

private static void removeAllDashboards() {
var dashboardStorage = StorageDispatcher.INSTANCE.getNoSqlStore()
.getDashboardStorage();
.getDashboardStorage();
dashboardStorage.findAll()
.forEach(dashboard -> dashboardStorage.deleteElementById(dashboard.getElementId()));
.forEach(dashboard -> dashboardStorage.deleteElementById(dashboard.getElementId()));
}

private static void removeAllAssets(String username) {
IGenericStorage genericStorage = StorageDispatcher.INSTANCE.getNoSqlStore()
.getGenericStorage();
.getGenericStorage();
try {
for (Map<String, Object> asset : genericStorage.findAll("asset-management")) {
genericStorage.delete((String) asset.get("_id"), (String) asset.get("_rev"));
Expand All @@ -203,4 +205,24 @@ private static void removeAllPipelineTemplates() {
.forEach(pipelineElementTemplateStorage::deleteElement);

}

private static void clearGenericStorage() {
var appDocTypesToDelete = List.of(
"asset-management",
"asset-sites"
);
var genericStorage = StorageDispatcher.INSTANCE.getNoSqlStore().getGenericStorage();

appDocTypesToDelete.forEach(docType -> {
try {
var allDocs = genericStorage.findAll(docType);
for (var doc : allDocs) {
genericStorage.delete(doc.get("_id").toString(), doc.get("_rev").toString());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
});

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.streampipes.rest.impl.admin;

import org.apache.streampipes.model.configuration.LocationConfig;
import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource;
import org.apache.streampipes.rest.security.AuthConstants;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v2/admin/location-config")
public class LocationConfigurationResource extends AbstractAuthGuardedRestResource {

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public LocationConfig getLocationConfig() {
return getSpCoreConfigurationStorage().get().getLocationConfig();
}

@PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize(AuthConstants.IS_ADMIN_ROLE)
public ResponseEntity<Void> updateGeneralConfiguration(@RequestBody LocationConfig config) {
var storage = getSpCoreConfigurationStorage();
var cfg = storage.get();
cfg.setLocationConfig(config);
storage.updateElement(cfg);

return ok();
}
}
31 changes: 31 additions & 0 deletions ui/cypress/support/utils/configuration/ConfigurationUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

export class ConfigurationUtils {
public static goToConfigurationExport() {
cy.visit('#/configuration/export');
}

public static goToSitesConfiguration() {
cy.visit('#/configuration/sites');
}

public static goToGeneralConfiguration() {
cy.visit('#/configuration/general');
}
}
65 changes: 65 additions & 0 deletions ui/cypress/support/utils/configuration/SiteUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

export class SiteUtils {
public static CHECKBOX_ENABLE_LOCATION_FEATURES =
'sites-enable-location-features-checkbox';
public static INPUT_TILE_SERVER_URL = 'sites-location-config-tile-server';

public static BUTTON_MANAGE_SITES = 'sites-manage-sites-button';
public static BUTTON_EDIT_SITE = 'sites-edit-button';
public static BUTTON_DELETE_SITE = 'sites-delete-button';
public static BUTTON_SITE_DIALOG_SAVE = 'sites-dialog-save-button';
public static BUTTON_SITE_DIALOG_CANCEL = 'sites-dialog-cancel-button';
public static BUTTON_SITE_DIALOG_REMOVE_AREA =
'sites-dialog-remove-area-button';
public static BUTTON_SITE_DIALOG_ADD_AREA = 'sites-dialog-add-area-button';

public static INPUT_SITE_DIALOG_SITE_INPUT = 'sites-dialog-site-input';
public static INPUT_SITE_DIALOG_NEW_AREA_INPUT =
'sites-dialog-new-area-input';

public static LABEL_TABLE_NAME = 'site-table-row-label';
public static LABEL_TABLE_AREA = 'site-table-row-areas';

public static enableGeoFeatures(tileServerUrl: string): void {
cy.dataCy(SiteUtils.CHECKBOX_ENABLE_LOCATION_FEATURES).click();
cy.dataCy(SiteUtils.INPUT_TILE_SERVER_URL).clear().type(tileServerUrl);
cy.dataCy('sites-location-features-button').click();
}

public static createNewSite(name: string, areas: string[]): void {
cy.dataCy(SiteUtils.BUTTON_MANAGE_SITES).click();
cy.dataCy(SiteUtils.INPUT_SITE_DIALOG_SITE_INPUT, { timeout: 2000 })
.clear()
.type(name);

areas.forEach(area => {
cy.dataCy(SiteUtils.INPUT_SITE_DIALOG_NEW_AREA_INPUT)
.clear()
.type(area);
cy.dataCy(SiteUtils.BUTTON_SITE_DIALOG_ADD_AREA).click();
});

cy.dataCy(this.BUTTON_SITE_DIALOG_SAVE).click();
}

public static openEditSiteDialog() {
cy.dataCy(SiteUtils.BUTTON_EDIT_SITE).first().click();
}
}
2 changes: 1 addition & 1 deletion ui/cypress/tests/assetManagement/createAsset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { AdapterBuilder } from '../../support/builder/AdapterBuilder';
import { ConnectUtils } from '../../support/utils/connect/ConnectUtils';
import { AssetUtils } from '../../support/utils/asset/AssetUtils';
import { DashboardUtils } from '../../support/utils/DashboardUtils';
import { ConfigurationUtils } from '../../support/utils/configuration/ConfigutationUtils';
import { ConfigurationUtils } from '../../support/utils/configuration/ConfigurationUtils';

describe('Creates a new adapter, add to assets and export assets', () => {
beforeEach('Setup Test', () => {
Expand Down
41 changes: 41 additions & 0 deletions ui/cypress/tests/configuration/sites/sites-geo-features.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import { SiteUtils } from '../../../support/utils/configuration/SiteUtils';
import { ConfigurationUtils } from '../../../support/utils/configuration/ConfigurationUtils';

describe('Test geo features settings', () => {
beforeEach('Setup Test', () => {
cy.initStreamPipesTest();
});

it('Perform Test', () => {
// enable geo features
ConfigurationUtils.goToSitesConfiguration();
SiteUtils.enableGeoFeatures('url');

ConfigurationUtils.goToGeneralConfiguration();
ConfigurationUtils.goToSitesConfiguration();

cy.dataCy(SiteUtils.CHECKBOX_ENABLE_LOCATION_FEATURES)
.find('input')
.should('be.checked');

cy.dataCy(SiteUtils.INPUT_TILE_SERVER_URL).should('have.value', 'url');
});
});
Loading

0 comments on commit dd8213e

Please sign in to comment.