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

feat: Asset and file directories can be modified from the UI #3414

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -18,11 +18,46 @@

package org.apache.streampipes.model.configuration;

import org.apache.streampipes.commons.environment.Environment;
import org.apache.streampipes.commons.environment.Environments;

import java.io.File;

public class DefaultGeneralConfig {

public GeneralConfig make() {
var generalConfig = new GeneralConfig();
generalConfig.setLinkSettings(new DefaultLinkSettings().make());
generalConfig.setAssetDir(makeAssetLocation());
generalConfig.setFilesDir(makeFileLocation());
return generalConfig;
}

public String makeAssetLocation() {
return makeStreamPipesHomeLocation()
+ "assets";
}

public String makeFileLocation() {
return makeStreamPipesHomeLocation()
+ "files";
}

private String makeStreamPipesHomeLocation() {
var userDefinedAssetDir = getEnvironment().getCoreAssetBaseDir();
var assetDirAppendix = getSpAssetDirAppendix();
if (userDefinedAssetDir.exists()) {
return userDefinedAssetDir.getValue() + assetDirAppendix;
} else {
return System.getProperty("user.home") + assetDirAppendix;
}
}

private String getSpAssetDirAppendix() {
return File.separator + ".streampipes" + File.separator;
}

private Environment getEnvironment() {
return Environments.getEnvironment();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.apache.streampipes.commons.environment.Environments;
import org.apache.streampipes.commons.random.TokenGenerator;

import java.io.File;

public class DefaultSpCoreConfiguration {

public SpCoreConfiguration make() {
Expand All @@ -33,33 +31,11 @@ public SpCoreConfiguration make() {
coreCfg.setMessagingSettings(new DefaultMessagingSettings().make());
coreCfg.setEmailConfig(EmailConfig.fromDefaults());
coreCfg.setEmailTemplateConfig(new DefaultEmailTemplateConfiguration().getDefaultTemplates());
coreCfg.setFilesDir(makeFileLocation());
coreCfg.setAssetDir(makeAssetLocation());
coreCfg.setLocalAuthConfig(LocalAuthConfig.fromDefaults(getJwtSecret()));

return coreCfg;
}

private String makeAssetLocation() {
return makeStreamPipesHomeLocation()
+ "assets";
}

private String makeFileLocation() {
return makeStreamPipesHomeLocation()
+ "files";
}

private String makeStreamPipesHomeLocation() {
var userDefinedAssetDir = getEnvironment().getCoreAssetBaseDir();
var assetDirAppendix = getSpAssetDirAppendix();
if (userDefinedAssetDir.exists()) {
return userDefinedAssetDir.getValue() + assetDirAppendix;
} else {
return System.getProperty("user.home") + assetDirAppendix;
}
}

private String getJwtSecret() {
var env = getEnvironment();
return env.getJwtSecret().getValueOrResolve(this::makeDefaultJwtSecret);
Expand All @@ -73,8 +49,4 @@ private Environment getEnvironment() {
return Environments.getEnvironment();
}

private String getSpAssetDirAppendix() {
return File.separator + ".streampipes" + File.separator;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class GeneralConfig {
private List<String> defaultUserRoles;
private LinkSettings linkSettings;

private String assetDir;
private String filesDir;

public GeneralConfig() {
}

Expand Down Expand Up @@ -113,4 +116,20 @@ public LinkSettings getLinkSettings() {
public void setLinkSettings(LinkSettings linkSettings) {
this.linkSettings = linkSettings;
}

public String getAssetDir() {
return assetDir;
}

public void setAssetDir(String assetDir) {
this.assetDir = assetDir;
}

public String getFilesDir() {
return filesDir;
}

public void setFilesDir(String filesDir) {
this.filesDir = filesDir;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public class SpCoreConfiguration {
private GeneralConfig generalConfig;
private LocationConfig locationConfig;

private boolean isConfigured;
private SpCoreConfigurationStatus serviceStatus;

private String assetDir;
private String filesDir;

private boolean isConfigured;
private SpCoreConfigurationStatus serviceStatus;

public SpCoreConfiguration() {
this.locationConfig = new LocationConfig(false, "", "");
}
Expand Down Expand Up @@ -100,22 +100,6 @@ public void setConfigured(boolean configured) {
isConfigured = configured;
}

public String getAssetDir() {
return assetDir;
}

public void setAssetDir(String assetDir) {
this.assetDir = assetDir;
}

public String getFilesDir() {
return filesDir;
}

public void setFilesDir(String filesDir) {
this.filesDir = filesDir;
}

public EmailTemplateConfig getEmailTemplateConfig() {
return this.emailTemplateConfig;
}
Expand All @@ -139,4 +123,20 @@ public LocationConfig getLocationConfig() {
public void setLocationConfig(LocationConfig locationConfig) {
this.locationConfig = locationConfig;
}

public String getAssetDir() {
return assetDir;
}

public void setAssetDir(String assetDir) {
this.assetDir = assetDir;
}

public String getFilesDir() {
return filesDir;
}

public void setFilesDir(String filesDir) {
this.filesDir = filesDir;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class AssetConstants {
.getNoSqlStore()
.getSpCoreConfigurationStorage()
.get()
.getGeneralConfig()
.getAssetDir();

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class FileConstants {
.getNoSqlStore()
.getSpCoreConfigurationStorage()
.get()
.getGeneralConfig()
.getFilesDir();

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.streampipes.service.core.migrations.v970.AddRolesToUserDbMigration;
import org.apache.streampipes.service.core.migrations.v970.DataExplorerDataViewMigration;
import org.apache.streampipes.service.core.migrations.v970.ModifyAssetLinkTypeMigration;
import org.apache.streampipes.service.core.migrations.v970.MoveDirectoryConfigurationMigration;
import org.apache.streampipes.service.core.migrations.v970.RemoveNodesFromOpcUaAdaptersMigration;

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

package org.apache.streampipes.service.core.migrations.v970;

import org.apache.streampipes.model.configuration.DefaultGeneralConfig;
import org.apache.streampipes.service.core.migrations.Migration;
import org.apache.streampipes.storage.api.ISpCoreConfigurationStorage;
import org.apache.streampipes.storage.management.StorageDispatcher;

import java.io.IOException;

public class MoveDirectoryConfigurationMigration implements Migration {

private final ISpCoreConfigurationStorage storage;

public MoveDirectoryConfigurationMigration() {
this.storage = StorageDispatcher.INSTANCE.getNoSqlStore().getSpCoreConfigurationStorage();
}

@Override
public boolean shouldExecute() {
var config = storage.get();
return config != null && config.getGeneralConfig().getAssetDir() == null;
}

@Override
public void executeMigration() throws IOException {
var config = storage.get();
config.getGeneralConfig().setFilesDir(new DefaultGeneralConfig().makeFileLocation());
config.getGeneralConfig().setAssetDir(new DefaultGeneralConfig().makeAssetLocation());

config.setAssetDir(null);
config.setFilesDir(null);

storage.updateElement(config);
}

@Override
public String getDescription() {
return "Moving asset directory to general config";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ export interface GeneralConfigModel {
defaultUserRoles: string[];
appName: string;
linkSettings: LinkSettings;
assetDir: string;
filesDir: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,34 @@
</mat-form-field>
</div>
</div>
<div class="subsection-title">Asset Directory</div>
<div class="warning mb-10">
Modification of the asset directory will be only applied
after restarting the core service.
</div>
<mat-form-field color="accent">
<input
formControlName="assetDir"
fxFlex
matInput
required
data-cy="general-config-asset-dir"
/>
</mat-form-field>
<div class="subsection-title">File Directory</div>
<div class="warning mb-10">
Modification of the file directory will be only applied
after restarting the core service.
</div>
<mat-form-field color="accent">
<input
formControlName="filesDir"
fxFlex
matInput
required
data-cy="general-config-files-dir"
/>
</mat-form-field>
</sp-split-section>
<sp-split-section
title="Registration"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export class GeneralConfigurationComponent implements OnInit {
defaultUserRoles: [UserRole.ROLE_PIPELINE_USER],
appName: this.appConstants.APP_NAME,
linkSettings: configs[0].linkSettings,
filesDir: configs[0].filesDir,
assetDir: configs[0].assetDir,
};
}
this.mailConfig = configs[1];
Expand Down Expand Up @@ -128,6 +130,20 @@ export class GeneralConfigurationComponent implements OnInit {
Validators.required,
),
);
this.parentForm.addControl(
'assetDir',
new UntypedFormControl(
this.generalConfig.assetDir,
Validators.required,
),
);
this.parentForm.addControl(
'filesDir',
new UntypedFormControl(
this.generalConfig.filesDir,
Validators.required,
),
);
this.parentForm.addControl(
'allowSelfRegistration',
new UntypedFormControl(
Expand Down Expand Up @@ -190,6 +206,8 @@ export class GeneralConfigurationComponent implements OnInit {
this.generalConfig.protocol = v.protocol;
this.generalConfig.port = v.port;
this.generalConfig.hostname = v.hostname;
this.generalConfig.assetDir = v.assetDir;
this.generalConfig.filesDir = v.filesDir;
this.generalConfig.allowPasswordRecovery =
v.allowPasswordRecovery;
this.generalConfig.allowSelfRegistration =
Expand Down
Loading