Skip to content

Commit

Permalink
Merge branch 'develop' of github.com-myrobotlab:MyRobotLab/myrobotlab…
Browse files Browse the repository at this point in the history
… into inmoov-and-statemachine-1
  • Loading branch information
supertick committed Oct 12, 2023
2 parents 1e04982 + c9dd10f commit 82d4c44
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 120 deletions.
205 changes: 102 additions & 103 deletions src/main/java/org/myrobotlab/framework/repo/IvyWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,113 +407,118 @@ public void installDependency(String location, ServiceDependency library) {
@Override
synchronized public void install(String location, String[] serviceTypes) throws IOException {

// try {
Set<ServiceDependency> targetLibraries = getUnfulfilledDependencies(serviceTypes);

Set<ServiceDependency> targetLibraries = getUnfulfilledDependencies(serviceTypes);

if (targetLibraries.size() == 0) {
StringBuilder sb = new StringBuilder();
for (String type : serviceTypes) {
if (type.lastIndexOf(".") > 0) {
sb.append(type.substring(type.lastIndexOf(".") + 1));
} else {
sb.append(type);
}
sb.append(" ");
if (targetLibraries.size() == 0) {
StringBuilder sb = new StringBuilder();
for (String type : serviceTypes) {
if (type.lastIndexOf(".") > 0) {
sb.append(type.substring(type.lastIndexOf(".") + 1));
} else {
sb.append(type);
}
info("%s already installed", sb.toString());
return;
sb.append(" ");
}
info("%s already installed", sb.toString());
return;
}

publishStatus(Status.newInstance(Repo.class.getSimpleName(), StatusLevel.INFO, Repo.INSTALL_START, String.format("starting install of %s", (Object[]) serviceTypes)));
publishStatus(Status.newInstance(Repo.class.getSimpleName(), StatusLevel.INFO, Repo.INSTALL_START, String.format("starting install of %s", (Object[]) serviceTypes)));

log.info("installing {} services into {}", serviceTypes.length, location);
log.info("installing {} services into {}", serviceTypes.length, location);

// create build files - generates appropriate ivy.xml and settings files
// this service file should be marked as dependencies all others
// should be marked as provided
// ??? do "provided" get incorporate in the resolve ?
createBuildFiles(location, serviceTypes);
// create build files - generates appropriate ivy.xml and settings files
// this service file should be marked as dependencies all others
// should be marked as provided
// ??? do "provided" get incorporate in the resolve ?
createBuildFiles(location, serviceTypes);

Platform platform = Platform.getLocalInstance();
Platform platform = Platform.getLocalInstance();

// templates [originalname](-[classifier])(-[revision]).[ext] parens are
// "optional"

List<String> cmd = new ArrayList<>();
cmd.add("-settings");
cmd.add(location + "/ivysettings.xml");
cmd.add("-ivy");
cmd.add(location + "/ivy.xml");
cmd.add("-retrieve");
cmd.add(location + "/jar" + "/[originalname].[ext]");

int msgLevel = 1;
if (log.isWarnEnabled() || log.isErrorEnabled()) {
msgLevel = Message.MSG_WARN;
cmd.add("-warn");
} else {
msgLevel = Message.MSG_INFO;
}
// templates [originalname](-[classifier])(-[revision]).[ext] parens are
// "optional"

StringBuilder sb = new StringBuilder();
sb.append("wget https://repo1.maven.org/maven2/org/apache/ivy/ivy/" + IVY_VERSION + "/ivy-" + IVY_VERSION + ".jar\n");
sb.append("java -jar ivy-" + IVY_VERSION + ".jar");
for (String s : cmd) {
sb.append(" ");
sb.append(s);
}
List<String> cmd = new ArrayList<>();
cmd.add("-settings");
cmd.add(location + "/ivysettings.xml");
cmd.add("-ivy");
cmd.add(location + "/ivy.xml");
cmd.add("-retrieve");
cmd.add(location + "/jar" + "/[originalname].[ext]");

sb.append("\n");
int msgLevel = Message.MSG_WARN;
if (log.isWarnEnabled() || log.isErrorEnabled()) {
msgLevel = Message.MSG_WARN;
cmd.add("-warn");
} else {
msgLevel = Message.MSG_INFO;
}

log.info("cmd {}", sb);
FileIO.toFile("libraries/install.sh", sb.toString().getBytes());
StringBuilder sb = new StringBuilder();
sb.append("wget https://repo1.maven.org/maven2/org/apache/ivy/ivy/" + IVY_VERSION + "/ivy-" + IVY_VERSION + ".jar\n");
sb.append("java -jar ivy-" + IVY_VERSION + ".jar");
for (String s : cmd) {
sb.append(" ");
sb.append(s);
}

Ivy ivy = Ivy.newInstance(); // <-- for future 2.5.x release
ivy.getLoggerEngine().pushLogger(new IvyWrapperLogger(msgLevel));
sb.append("\n");

ResolveReport report = null;
List<String> err = new ArrayList<>();
try {
report = Main.run(cmd.toArray(new String[cmd.size()]));
} catch (Exception e) {
err.add(e.toString());
}
log.info("cmd {}", sb);
FileIO.toFile("libraries/install.sh", sb.toString().getBytes());

// if no errors -h
// mark "service" as installed
// mark all libraries as installed
Ivy ivy = Ivy.newInstance(); // <-- for future 2.5.x release
ivy.getLoggerEngine().pushLogger(new IvyWrapperLogger(msgLevel));

if (report != null) {
List<String> problems = report.getAllProblemMessages();
for (String problem : problems) {
if (!problem.startsWith("WARN: symlinkmass")) {
err.add(problem);
}
ResolveReport report = null;
List<String> err = new ArrayList<>();
try {
report = Main.run(cmd.toArray(new String[0]));
} catch (Exception e) {
err.add(e.toString());
}

// if no errors -h
// mark "service" as installed
// mark all libraries as installed

if (report != null) {
List<String> problems = report.getAllProblemMessages();
for (String problem : problems) {
if (!problem.startsWith("WARN: symlinkmass")) {
err.add(problem);
}
}
}

if (err.size() > 0) {
log.error("had errors - repo will not be updated. Errors:\n{}", err);
} else {

// TODO - promote to Repo.setInstalled
for (ServiceDependency library : targetLibraries) {
// set as installed & save state
library.setInstalled(true);
installedLibraries.put(library.toString(), library);
info("installed %s platform %s", library, platform.getPlatformId());
}
save();
if (err.size() > 0) {
log.error("had errors - repo will not be updated. Errors:\n{}", err);
} else {

// TODO - promote to Repo.setInstalled
for (ServiceDependency library : targetLibraries) {
// set as installed & save state
library.setInstalled(true);
installedLibraries.put(library.toString(), library);
info("installed %s platform %s", library, platform.getPlatformId());
}
save();
}

if (report == null) {
String errorDetail = String.format("there was problems resolving dependencies %s", (Object[]) serviceTypes);
log.error(errorDetail);
publishStatus(Status.newInstance(Repo.class.getSimpleName(), StatusLevel.ERROR, Repo.INSTALL_FINISHED,
errorDetail));
throw new RuntimeException(errorDetail);
} else {
if (report == null) {
String errorDetail = String.format("There were problems resolving dependencies %s", (Object[]) serviceTypes);
log.error(errorDetail);
publishStatus(Status.newInstance(Repo.class.getSimpleName(), StatusLevel.ERROR, Repo.INSTALL_FINISHED, errorDetail));
throw new RuntimeException(errorDetail);
} else {

ArtifactDownloadReport[] artifacts = report.getAllArtifactsReports();
for (int i = 0; i < artifacts.length; ++i) {
ArtifactDownloadReport ar = artifacts[i];
Artifact artifact = ar.getArtifact();
// String filename =
// IvyPatternHelper.substitute("[originalname].[ext]",
// artifact);

ArtifactDownloadReport[] artifacts = report.getAllArtifactsReports();
for (int i = 0; i < artifacts.length; ++i) {
Expand All @@ -523,28 +528,22 @@ synchronized public void install(String location, String[] serviceTypes) throws
// IvyPatternHelper.substitute("[originalname].[ext]",
// artifact);

File file = ar.getLocalFile();
String filename = file.getAbsoluteFile().getAbsolutePath();
log.info("{}", filename);

if ("zip".equalsIgnoreCase(artifact.getExt())) {
info("unzipping %s", filename);
try {
Zip.unzip(filename, "./");
info("unzipped %s", filename);
} catch (Exception e) {
log.error("unable to unzip file {}", filename, e);
}
if ("zip".equalsIgnoreCase(artifact.getExt())) {
info("unzipping %s", filename);
try {
Zip.unzip(filename, "./");
info("unzipped %s", filename);
} catch (Exception e) {
log.error("unable to unzip file {}", filename, e);
throw new IOException(String.format("unable to unzip file %s", filename));
}
}

publishStatus(Status.newInstance(Repo.class.getSimpleName(), StatusLevel.INFO, Repo.INSTALL_FINISHED, String.format("finished install of %s", (Object[]) serviceTypes)));
}
// } catch (Exception e) {
// error(e.getMessage());
// log.error(e.getMessage(), e);
// }

publishStatus(Status.newInstance(Repo.class.getSimpleName(), StatusLevel.INFO, Repo.INSTALL_FINISHED, String.format("finished install of %s", (Object[]) serviceTypes)));
}
}

private void publishStatus(String msg, int level) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/myrobotlab/framework/repo/Repo.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public abstract class Repo {
*/
protected static String LOCATION = null;

List<Status> errors = new ArrayList<Status>();
protected List<Status> errors = new ArrayList<Status>();

Map<String, ServiceDependency> installedLibraries = new TreeMap<String, ServiceDependency>();
protected Map<String, ServiceDependency> installedLibraries = new TreeMap<String, ServiceDependency>();

public String getRepoPath() {
return LOCATION + File.separator + REPO_STATE_FILE_NAME;
Expand Down Expand Up @@ -403,7 +403,7 @@ synchronized public void installDependency(String libraries, String[] installDep

abstract public void installDependency(String location, ServiceDependency serviceTypes);

abstract public void install(String location, String[] serviceTypes) throws Exception;
abstract public void install(String location, String[] serviceTypes) throws IOException;

synchronized public void install(String[] serviceTypes) throws Exception {
install(getInstallDir(), serviceTypes);
Expand Down
33 changes: 24 additions & 9 deletions src/main/java/org/myrobotlab/service/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.myrobotlab.logging.Logging;
import org.myrobotlab.logging.LoggingFactory;
import org.myrobotlab.service.config.LogConfig;
import org.myrobotlab.service.config.RuntimeConfig;
import org.slf4j.Logger;

import ch.qos.logback.classic.spi.ILoggingEvent;
Expand Down Expand Up @@ -92,11 +93,8 @@ public String toString() {
*/
long lastPublishLogTimeTs = 0;

/**
* current log level
*/
String logLevel = null;


/**
* max size of log buffer
*/
Expand All @@ -114,8 +112,10 @@ public Log(String n, String id) {

public String getLogLevel() {
Logging logging = LoggingFactory.getInstance();
logLevel = logging.getLevel();
return logLevel;
if (config != null) {
config.level = logging.getLevel();
}
return logging.getLevel();
}

@Override
Expand Down Expand Up @@ -262,6 +262,18 @@ public void setRootLogLevel(String level) {
getLogLevel();
broadcastState();
}

public LogConfig apply(LogConfig c) {
super.apply(c);
if (c.level != null) {
setRootLogLevel(c.level);
}
return c;
}

public LogConfig getConfig() {
return config;
}

@Override
public void setName(String name) {
Expand Down Expand Up @@ -314,14 +326,17 @@ public static void main(String[] args) {
try {

// Log4jLoggerAdapter blah;

Runtime runtime = Runtime.getInstance();
RuntimeConfig config = runtime.getConfig();
config.resource = "src/main/resources/resource";
runtime.apply(config);

Runtime.start("log", "Log");
Runtime.start("python", "Python");
WebGui webgui = (WebGui) Runtime.create("webgui", "WebGui");
webgui.autoStartBrowser(false);
webgui.startService();
Runtime runtime = Runtime.getInstance();
runtime.startInteractiveMode();

log.info("this is an info test");
log.warn("this is an warn test");
log.error("this is an error test");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/myrobotlab/service/config/LogConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public class LogConfig extends ServiceConfig {
/**
* level of log error, warn, info, debug
*/
String level = "info";
public String level = "info";

}
6 changes: 3 additions & 3 deletions src/main/resources/resource/WebGui/app/service/js/LogGui.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('mrlapp.service.LogGui', []).controller('LogGuiCtrl', ['$scope', '$log', 'mrl', function($scope, $log, mrl) {
$log.info('LogGuiCtrl')
angular.module('mrlapp.service.LogGui', []).controller('LogGuiCtrl', ['$scope', 'mrl', function($scope, mrl) {
console.info('LogGuiCtrl')
var _self = this
var msg = this.msg

Expand Down Expand Up @@ -116,7 +116,7 @@ angular.module('mrlapp.service.LogGui', []).controller('LogGuiCtrl', ['$scope',
}
break
default:
$log.error("ERROR - unhandled method " + $scope.name + "." + msg.method)
console.error("ERROR - unhandled method " + $scope.name + "." + msg.method)
break
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<button class="btn btn-default" ng-show="!service.isLogging" ng-click="msg.startLogging();msg.broadcastState()">start logging</button>
<button class="btn btn-default" ng-show="service.isLogging" ng-click="msg.stopLogging();msg.broadcastState()">stop logging</button>
<div class="btn-group" uib-dropdown>
<button id="level-button" type="button" ng-class="{'btn': true, 'btn-success': service.logLevel == 'DEBUG','btn-default': service.logLevel == 'INFO', 'btn-warning': service.logLevel == 'WARN', 'btn-danger': service.logLevel == 'ERROR','small': true}" uib-dropdown-toggle>log level - {{service.logLevel}}</button>
<button id="level-button" type="button" ng-class="{'btn': true, 'btn-success': service.logLevel == 'DEBUG','btn-default': service.logLevel == 'INFO', 'btn-warning': service.logLevel == 'WARN', 'btn-danger': service.logLevel == 'ERROR','small': true}" uib-dropdown-toggle>log level - {{service.config.level}}</button>
<ul uib-dropdown-menu role="menu">
<li>
<button class="btn btn-success col-md-12" ng-click="msg.setRootLogLevel('debug')">DEBUG</button>
Expand Down

0 comments on commit 82d4c44

Please sign in to comment.