-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gerd Wuetherich
committed
Jun 10, 2019
1 parent
588af82
commit fcc9791
Showing
19 changed files
with
684 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ver/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/ExtensionIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* slizaa-server-main - Slizaa Static Software Analysis Tools | ||
* Copyright © 2019 Code-Kontor GmbH and others ([email protected]) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.codekontor.slizaa.server; | ||
|
||
import com.google.common.base.Preconditions; | ||
import io.codekontor.slizaa.server.service.extensions.IExtensionIdentifier; | ||
import io.codekontor.slizaa.server.service.extensions.Version; | ||
|
||
public class ExtensionIdentifier implements IExtensionIdentifier { | ||
|
||
private String symbolicName; | ||
|
||
private Version version; | ||
|
||
public ExtensionIdentifier(String symbolicName, String version) { | ||
this.symbolicName = Preconditions.checkNotNull(symbolicName); | ||
this.version = new Version(Preconditions.checkNotNull(version)); | ||
} | ||
|
||
@Override | ||
public String getSymbolicName() { | ||
return symbolicName; | ||
} | ||
|
||
@Override | ||
public Version getVersion() { | ||
return version; | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
...r/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaBackendCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/** | ||
* slizaa-server-main - Slizaa Static Software Analysis Tools | ||
* Copyright © 2019 Code-Kontor GmbH and others ([email protected]) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.codekontor.slizaa.server; | ||
|
||
import io.codekontor.slizaa.server.service.backend.IBackendService; | ||
import io.codekontor.slizaa.server.service.backend.IModifiableBackendService; | ||
import io.codekontor.slizaa.server.service.extensions.IExtension; | ||
import io.codekontor.slizaa.server.service.extensions.IExtensionIdentifier; | ||
import io.codekontor.slizaa.server.service.extensions.IExtensionService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.shell.standard.ShellCommandGroup; | ||
import org.springframework.shell.standard.ShellComponent; | ||
import org.springframework.shell.standard.ShellMethod; | ||
import org.springframework.shell.standard.ShellOption; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@ShellComponent | ||
@ShellCommandGroup("Slizaa Backend Commands") | ||
public class SlizaaBackendCommands { | ||
|
||
@Autowired(required = false) | ||
private IModifiableBackendService _modifiableBackendService; | ||
|
||
@Autowired | ||
private IBackendService _backendService; | ||
|
||
@Autowired | ||
private IExtensionService _extensionService; | ||
|
||
@ShellMethod(value = "List all available backend extensions.", key="listAvailableExtensions") | ||
public String listAvailableExtensions() { | ||
|
||
// | ||
StringBuffer stringBuffer = new StringBuffer(); | ||
stringBuffer.append("Available Backend Extensions:\n"); | ||
_extensionService.getExtensions().forEach(extension -> { | ||
stringBuffer.append(String.format(" - %1$s_%2$s (Symbolic name: %1$s, version: %2$s)\n", extension.getSymbolicName(), extension.getVersion())); | ||
}); | ||
return stringBuffer.toString(); | ||
} | ||
|
||
@ShellMethod(value = "List installed extensions.", key="listInstalledExtensions") | ||
public String listInstalledExtensions() { | ||
|
||
StringBuffer stringBuffer = new StringBuffer(); | ||
stringBuffer.append("Installed Backend Extensions:\n"); | ||
_backendService.getInstalledExtensions().forEach(extension -> { | ||
stringBuffer.append(extension + "\n"); | ||
}); | ||
|
||
|
||
return stringBuffer.toString(); | ||
} | ||
|
||
@ShellMethod(value = "Install backend extensions.", key="installExtensions") | ||
public String installExtensions(@ShellOption({"-e", "--extensions"}) String[] extensions) { | ||
|
||
// fail fast | ||
if (_modifiableBackendService == null) { | ||
return cannotExecuteCommand("Backend is not modifiable."); | ||
} | ||
|
||
// | ||
List<IExtensionIdentifier> extensionIdList = new ArrayList<>(); | ||
|
||
for (int i = 0; i < extensions.length; i++) { | ||
String extension = extensions[i]; | ||
String[] split = extension.split("_"); | ||
if (split.length != 2) { | ||
return cannotExecuteCommand(String.format("Invalid parameter value '%s'.", extension)); | ||
} | ||
extensionIdList.add(new ExtensionIdentifier(split[0], split[1])); | ||
} | ||
|
||
// | ||
List<IExtension> extensionsToInstall = _extensionService.getExtensions(extensionIdList); | ||
_modifiableBackendService.installExtensions(extensionsToInstall); | ||
|
||
StringBuffer stringBuffer = new StringBuffer(); | ||
stringBuffer.append("Installed Backend Extensions:\n"); | ||
_modifiableBackendService.getInstalledExtensions().forEach(extension -> { | ||
stringBuffer.append(extension + "\n"); | ||
}); | ||
|
||
|
||
return stringBuffer.toString(); | ||
} | ||
|
||
/** | ||
* Checks if the backend is configured properly. | ||
* | ||
* @return <code>true</code> if the backend is configured properly. | ||
*/ | ||
private String checkBackendConfigured() { | ||
if (!_backendService.hasInstalledExtensions()) { | ||
return cannotExecuteCommand("The Slizaa Server has not been configured properly: There are not installed backend extensions.\n"); | ||
} | ||
return null; | ||
} | ||
|
||
private String cannotExecuteCommand(String msg) { | ||
StringBuffer stringBuffer = new StringBuffer(); | ||
stringBuffer.append("Can not execute command.\n"); | ||
stringBuffer.append(msg + "\n"); | ||
return stringBuffer.toString(); | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
...aa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaGraphDatabaseCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* slizaa-server-main - Slizaa Static Software Analysis Tools | ||
* Copyright © 2019 Code-Kontor GmbH and others ([email protected]) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.codekontor.slizaa.server; | ||
|
||
import io.codekontor.slizaa.server.descr.ContentDefinition; | ||
import io.codekontor.slizaa.server.descr.GraphDatabase; | ||
import io.codekontor.slizaa.server.service.backend.IModifiableBackendService; | ||
import io.codekontor.slizaa.server.service.slizaa.ISlizaaService; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.shell.standard.ShellCommandGroup; | ||
import org.springframework.shell.standard.ShellComponent; | ||
import org.springframework.shell.standard.ShellMethod; | ||
|
||
import java.util.Collections; | ||
|
||
@ShellComponent | ||
@ShellCommandGroup("Slizaa Graph Databases Commands") | ||
public class SlizaaGraphDatabaseCommands { | ||
|
||
@Autowired(required = false) | ||
private IModifiableBackendService _modifiableBackendService; | ||
|
||
@Autowired | ||
private ISlizaaService _slizaaService; | ||
|
||
@ShellMethod(value = "List all configured graph databases.", key="listDBs") | ||
public String listDBs() { | ||
|
||
// check the backend configuration | ||
String checkBackendConfigured = checkBackendConfigured(); | ||
if (checkBackendConfigured != null) { | ||
return checkBackendConfigured; | ||
} | ||
|
||
// | ||
return dumpGraphDatabases(); | ||
} | ||
|
||
@ShellMethod(value = "Create a new graph databases.", key="createDB") | ||
public String createDB(String identifier) { | ||
|
||
// check the backend configuration | ||
String checkBackendConfigured = checkBackendConfigured(); | ||
if (checkBackendConfigured != null) { | ||
return checkBackendConfigured; | ||
} | ||
|
||
// | ||
_slizaaService.newGraphDatabase(identifier); | ||
|
||
// return the result | ||
return dumpGraphDatabases(); | ||
|
||
} | ||
|
||
@NotNull | ||
private String dumpGraphDatabases() { | ||
// | ||
StringBuffer stringBuffer = new StringBuffer(); | ||
stringBuffer.append("Graph Databases:\n"); | ||
|
||
_slizaaService.getGraphDatabases().forEach(db -> { | ||
|
||
ContentDefinition contentDefinition = | ||
db.getContentDefinition() != null ? | ||
new ContentDefinition( | ||
db.getContentDefinition().getContentDefinitionProviderFactory().getFactoryId(), | ||
db.getContentDefinition().toExternalRepresentation()) : | ||
null; | ||
|
||
GraphDatabase graphDatabase = new GraphDatabase( | ||
db.getIdentifier(), | ||
contentDefinition, | ||
Collections.emptyList(), | ||
db.getState().name(), | ||
db.getPort(), | ||
Collections.emptyList()); | ||
|
||
stringBuffer.append(" - " + graphDatabase.toString() + "\n"); | ||
}); | ||
|
||
return stringBuffer.toString(); | ||
} | ||
|
||
/** | ||
* Checks if the backend is configured properly. | ||
* | ||
* @return <code>true</code> if the backend is configured properly. | ||
*/ | ||
private String checkBackendConfigured() { | ||
if (!_slizaaService.getBackendService().hasInstalledExtensions()) { | ||
return cannotExecuteCommand("The Slizaa Server has not been configured properly: There are not installed backend extensions.\n"); | ||
} | ||
return null; | ||
} | ||
|
||
private String cannotExecuteCommand(String msg) { | ||
StringBuffer stringBuffer = new StringBuffer(); | ||
stringBuffer.append("Can not execute command.\n"); | ||
stringBuffer.append(msg + "\n"); | ||
return stringBuffer.toString(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaQuit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* slizaa-server-main - Slizaa Static Software Analysis Tools | ||
* Copyright © 2019 Code-Kontor GmbH and others ([email protected]) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.codekontor.slizaa.server; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.shell.standard.ShellCommandGroup; | ||
import org.springframework.shell.standard.ShellComponent; | ||
import org.springframework.shell.standard.ShellMethod; | ||
import org.springframework.shell.standard.commands.Quit; | ||
|
||
@ShellComponent | ||
@ShellCommandGroup("Built-In Commands") | ||
public class SlizaaQuit implements Quit.Command { | ||
|
||
@Autowired | ||
private ConfigurableApplicationContext applicationContext; | ||
|
||
@ShellMethod( | ||
value = "Exit the shell.", | ||
key = {"quit", "exit"} | ||
) | ||
public void quit() { | ||
new Thread(() -> { | ||
try { | ||
SpringApplication.exit(applicationContext, () -> 0); | ||
System.exit(0); | ||
} catch (Exception e) { | ||
|
||
} | ||
}).start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.