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

IKASAN-2363 adding feature to persist the ikasan version to the file … #1280

Merged
merged 2 commits into from
Mar 20, 2024
Merged
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
25 changes: 13 additions & 12 deletions ikasaneip/cli/shell/jar/Readme.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@
package org.ikasan.cli.shell.command;

import org.ikasan.cli.shell.operation.model.ProcessType;
import org.ikasan.cli.shell.version.service.IkasanVersionService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.shell.command.annotation.Command;
import org.springframework.shell.command.annotation.Option;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;

/**
* Commands to start and stop the integration module.
Expand All @@ -63,6 +61,12 @@ public class ModuleCommand extends ActionCommand
@Value("${module.java.command:null}")
String moduleJavaCommand;

@Value("${persistence.dir}")
private String persistenceDir;

@Value("${pom.version}")
private String pomVersion;

/**
* Start Integration Module.
* @param altModuleName
Expand All @@ -89,6 +93,9 @@ JSONObject _startmodule(String altModuleName, String altCommand)
command = altCommand;
}

// Write the ikasan version to the non-transient persistent file system.
IkasanVersionService.instance(this.persistenceDir).writeVersion(this.pomVersion);

return this.start(this.processType, name, command);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* $Id$
* $URL$
*
* ====================================================================
* Ikasan Enterprise Integration Platform
*
* Distributed under the Modified BSD License.
* Copyright notice: The copyright for this software and a full listing
* of individual contributors are as shown in the packaged copyright.txt
* file.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of the ORGANIZATION nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
package org.ikasan.cli.shell.command;

import org.ikasan.cli.shell.version.model.IkasanVersion;
import org.ikasan.cli.shell.version.service.IkasanVersionService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.shell.command.annotation.Command;

/**
* Command to get the Ikasan version of the module.
*
* @author Ikasan Development Team
*/
@Command
public class VersionCommand
{
@Value("${persistence.dir}")
private String persistenceDir;

/**
* Get the Ikasan version of the module.
*
* @return the module version
*/
@Command(description = "Get the Ikasan version of the module", group = "Ikasan Commands", command = "version")
public String version() {
IkasanVersion ikasanVersion = IkasanVersionService.instance(this.persistenceDir).find();

if(ikasanVersion != null) {
return ikasanVersion.getVersion();
}
else {
return "The module version is not available!";
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ logging.level.org.jline=ERROR

shell.history.file=log/ikasan-shell.log

[email protected]@

# default some variables
module.jar.name=${module.name}
h2.jar.name=h2-*.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ logging.level.org.ikasan=INFO
logging.file=logs/application.log
logging.level.org.ikasan.cli.shell=ERROR

[email protected]@

# Ikasan Shell
h2.java.command=java -Dmodule.name=filesystem-im -classpath ./lib/h2-1.4.200.jar org.h2.tools.Server -ifNotExists -tcp -tcpAllowOthers -tcpPort 8888
module.java.command=java -server -Xms256m -Xmx256m -XX:MaxMetaspaceSize=128m -Dspring.jta.logDir=./persistence/filesystem-im-ObjectStore -Dorg.apache.activemq.SERIALIZABLE_PACKAGES=* -Dmodule.name=filesystem-im -jar ./lib/filesystem-im-1.0.0-SNAPSHOT.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public MigrationPersistenceDaoImpl(String persistenceDir) {
@Override
public void save(IkasanMigration ikasanMigration)
{
String path = getPidFQN(ikasanMigration.getType()
String path = getMigrationManifestFilePath(ikasanMigration.getType()
, ikasanMigration.getSourceVersion(), ikasanMigration.getTargetVersion());

try(Output output = new Output(new FileOutputStream(path))) {
Expand All @@ -114,7 +114,7 @@ public void save(IkasanMigration ikasanMigration)

@Override
public IkasanMigration find(String type, String sourceVersion, String targetVersion) {
String path = getPidFQN(type, sourceVersion, targetVersion);
String path = getMigrationManifestFilePath(type, sourceVersion, targetVersion);
try (Input input = new Input(new FileInputStream(path))) {
return this.objectMapper.readValue(input, IkasanMigration.class);
}
Expand All @@ -126,7 +126,7 @@ public IkasanMigration find(String type, String sourceVersion, String targetVers

@Override
public void delete(String type, String sourceVersion, String targetVersion) {
String path = getPidFQN(type, sourceVersion, targetVersion);
String path = getMigrationManifestFilePath(type, sourceVersion, targetVersion);
try {
Files.delete(Path.of(path));
}
Expand All @@ -135,7 +135,7 @@ public void delete(String type, String sourceVersion, String targetVersion) {
}
}

protected String getPidFQN(String type, String sourceVersion, String targetVersion) {
protected String getMigrationManifestFilePath(String type, String sourceVersion, String targetVersion) {
return persistenceDir + FileSystems.getDefault().getSeparator() + type + "_" + sourceVersion + "_" + targetVersion;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
* @author Ikasan Development Team
*/
public interface MigrationService {

/**
* Returns an instance of MigrationService.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* $Id$
* $URL$
*
* ====================================================================
* Ikasan Enterprise Integration Platform
*
* Distributed under the Modified BSD License.
* Copyright notice: The copyright for this software and a full listing
* of individual contributors are as shown in the packaged copyright.txt
* file.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of the ORGANIZATION nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
package org.ikasan.cli.shell.version.dao;

import org.ikasan.cli.shell.migration.model.IkasanMigration;
import org.ikasan.cli.shell.version.model.IkasanVersion;

/**
* Process persistence contract.
*
* @author Ikasan Development Team
*/
public interface IkasanVersionPersistenceDao
{
/**
* Saves the given IkasanVersion object.
*
* @param ikasanVersion the IkasanVersion object to be saved
*/
void save(IkasanVersion ikasanVersion);


/**
* Finds the IkasanVersion object.
*
* @return the found IkasanVersion object, or null if not found
*/
IkasanVersion find();


/**
* Deletes IkasanVersion.
*/
void delete();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* $Id$
* $URL$
*
* ====================================================================
* Ikasan Enterprise Integration Platform
*
* Distributed under the Modified BSD License.
* Copyright notice: The copyright for this software and a full listing
* of individual contributors are as shown in the packaged copyright.txt
* file.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of the ORGANIZATION nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
package org.ikasan.cli.shell.version.dao;

import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.ikasan.cli.shell.migration.model.IkasanMigration;
import org.ikasan.cli.shell.version.model.IkasanVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

/**
* Serialiser for IkasanProcess.
*
* @author Ikasan Development Team
*/
public class IkasanVersionPersistenceDaoImpl implements IkasanVersionPersistenceDao
{
/** logger instance */
private static Logger logger = LoggerFactory.getLogger(IkasanVersionPersistenceDaoImpl.class);

private ObjectMapper objectMapper = new ObjectMapper();

/** persistence directory */
private String persistenceDir;

private File persistenceDirFile;


/**
* Constructor
* @param persistenceDir
*/
public IkasanVersionPersistenceDaoImpl(String persistenceDir) {
this.persistenceDir = persistenceDir;
if(persistenceDir == null) {
throw new IllegalArgumentException("persistence directory cannot be 'null");
}

this.persistenceDirFile = new File(persistenceDir);
if(!persistenceDirFile.exists()) {
persistenceDirFile.mkdirs();
File directorySafeGuardFile = new File(this.persistenceDir + "/DO_NOT_DELETE_ANY_FILES_IN_THIS_DIRECTORY");
if(!directorySafeGuardFile.exists()) {
try {
directorySafeGuardFile.createNewFile();
}
catch (IOException e) {
logger.warn("An error has occurred creating the directory safe guard file!", e);
}
}
}
}

@Override
public void save(IkasanVersion ikasanVersion)
{
String path = getVersionFilePath();

try(Output output = new Output(new FileOutputStream(path))) {
objectMapper.writeValue(output, ikasanVersion);
}
catch(IOException e) {
throw new RuntimeException("Failed to save the IkasanProcess", e);
}
}

@Override
public IkasanVersion find() {
String path = getVersionFilePath();
try (Input input = new Input(new FileInputStream(path))) {
return this.objectMapper.readValue(input, IkasanVersion.class);
}
catch(IOException e) {
logger.debug("File [" + path + "] not found", e);
return null;
}
}

@Override
public void delete() {
String path = getVersionFilePath();
try {
Files.delete(Path.of(path));
}
catch(IOException e) {
logger.warn("Failed to delete [" + path + "] file may be missing or some other IO issue" + e.getMessage());
}
}

protected String getVersionFilePath() {
return persistenceDir + FileSystems.getDefault().getSeparator() + "ikasan-version.mf";
}

}
Loading