Skip to content

Commit

Permalink
Service monitoring improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
fvilla committed Nov 20, 2023
1 parent 25b91aa commit 22ccc35
Show file tree
Hide file tree
Showing 14 changed files with 540 additions and 414 deletions.
407 changes: 207 additions & 200 deletions kcli/src/main/java/org/integratedmodelling/kcli/engine/Engine.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.integratedmodelling.klab.api.services;

import java.io.Serializable;

import org.integratedmodelling.klab.api.scope.ServiceScope;

import java.io.Serializable;

/**
* Services may be locally implemented or clients to remote services: each service implementation
* should provide both forms. The latter ones must publish a URL. In all cases they are added in
Expand All @@ -19,6 +19,14 @@
*/
public interface KlabService extends Service {

enum Type {
REASONER,
RESOURCES,
RESOLVER,
RUNTIME,
COMMUNITY
}

/**
* At the very minimum, each service advertises its type and local name.
*
Expand All @@ -27,6 +35,8 @@ public interface KlabService extends Service {
*/
interface ServiceCapabilities extends Serializable {

Type getType();

String getLocalName();

String getServiceName();
Expand Down Expand Up @@ -54,7 +64,6 @@ interface ServiceCapabilities extends Serializable {
*/
String getLocalName();


/**
* Each service operates under a root scope that is used to report issues, talk to clients and
* derive child scopes for users and when appropriate, sessions and contexts.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.integratedmodelling.klab.api.services.runtime;

import java.io.Serializable;

import org.integratedmodelling.klab.api.scope.Scope;
import org.integratedmodelling.klab.api.services.runtime.impl.MessageImpl;
import org.integratedmodelling.klab.api.utils.Utils;

import java.io.Serializable;

/**
* Messages exchanged between the engine and its clients.
*
Expand Down Expand Up @@ -46,6 +46,10 @@ enum MessageClass {
*/
UserContextDefinition,

/**
* Any event referring to a service
*/
ServiceLifecycle,
/**
*
*/
Expand Down Expand Up @@ -130,6 +134,11 @@ enum MessageType {
*/
ConsoleCreated, ConsoleClosed, CommandRequest, CommandResponse,

/*
* Service messages, coming with service capabilities
*/
ServiceInitializing, ServiceAvailable, ServiceUnavailable,

/*
* UserContextChange-class types.
*/
Expand Down Expand Up @@ -475,7 +484,7 @@ public static MessageImpl create(String identity, Object... o) {
ret.setRepeatability((Repeatability) ob);
} else if (ob instanceof Notification) {
notype = ((Notification) ob).getType();
ret.setPayload(((Notification) ob).getMessage());
ret.setPayload(ob);
} else if (ob != null) {
if (ret.getPayload() == null) {
ret.setPayload(ob);
Expand Down Expand Up @@ -510,7 +519,7 @@ public static MessageImpl create(Notification notification, String identity) {
MessageImpl ret = new MessageImpl();
ret.setIdentity(identity);
ret.setMessageClass(MessageClass.Notification);
ret.setPayload(notification.getMessage());
ret.setPayload(notification);
ret.setPayloadClass("String");

if (notification.getLevel().equals(Notification.Level.Debug)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,148 +7,150 @@
import org.integratedmodelling.klab.api.scope.ServiceScope;
import org.integratedmodelling.klab.api.services.KlabService;
import org.integratedmodelling.klab.api.services.runtime.Channel;
import org.integratedmodelling.klab.api.services.runtime.Message;

import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.*;
import java.util.function.BiConsumer;

public abstract class LocalServiceScope extends Monitor implements ServiceScope {

KlabService service;
Status status;

class LocalService implements ServiceIdentity {

Date boot = new Date();
KlabService service;
Scope delegate;

public LocalService(KlabService service) {
this.service = service;
}

@Override
public boolean stop() {
return false;
}

@Override
public Channel getMonitor() {
return LocalServiceScope.this;
}

@Override
public Parameters<String> getState() {
return getData();
}

@Override
public Type getIdentityType() {
return Type.SERVICE;
}

@Override
public String getId() {
return service.getLocalName();
}

@Override
public Identity getParentIdentity() {
return null;
}

@Override
public boolean is(Type type) {
return type == Type.SERVICE;
}

@Override
public <T extends Identity> T getParentIdentity(Class<T> type) {
return null;
}

@Override
public String getName() {
return service.getServiceName();
}

@Override
public Date getBootTime() {
return boot;
}

@Override
public Collection<String> getUrls() {
return Collections.singleton(service.getUrl());
}

@Override
public boolean isOnline() {
return true;
}

@Override
public Parameters<String> getData() {
return LocalServiceScope.this.data;
}

}

public LocalServiceScope(Class<? extends KlabService> serviceClass) {
this.serviceClass = serviceClass;
}

private Parameters<String> data = Parameters.create();
private Identity serviceIdentity;
private Class<? extends KlabService> serviceClass;

@Override
public Parameters<String> getData() {
return data;
}

@Override
public boolean isLocal() {
return true;
}

@Override
public boolean isExclusive() {
return false;
}

@Override
public boolean isDedicated() {
return true;
}

@Override
public Status getStatus() {
return status;
}

@Override
public <T extends KlabService> Collection<T> getServices(Class<T> serviceClass) {
// TODO if a service resolver is available to the service, that should be used.
return Collections.singleton(getService(serviceClass));
}

@Override
public Identity getIdentity() {
if (this.serviceIdentity != null) {
this.serviceIdentity = new LocalService(getService(this.serviceClass));
}
return this.serviceIdentity;
}

@Override
public void setStatus(Status status) {
this.status = status;
}

@Override
public void setData(String key, Object value) {
this.data.put(key, value);
}
KlabService service;
Status status;

class LocalService implements ServiceIdentity {

Date boot = new Date();
KlabService service;
Scope delegate;

public LocalService(KlabService service) {
this.service = service;
}

@Override
public boolean stop() {
return false;
}

@Override
public Channel getMonitor() {
return LocalServiceScope.this;
}

@Override
public Parameters<String> getState() {
return getData();
}

@Override
public Type getIdentityType() {
return Type.SERVICE;
}

@Override
public String getId() {
return service.getLocalName();
}

@Override
public Identity getParentIdentity() {
return null;
}

@Override
public boolean is(Type type) {
return type == Type.SERVICE;
}

@Override
public <T extends Identity> T getParentIdentity(Class<T> type) {
return null;
}

@Override
public String getName() {
return service.getServiceName();
}

@Override
public Date getBootTime() {
return boot;
}

@Override
public Collection<String> getUrls() {
return Collections.singleton(service.getUrl());
}

@Override
public boolean isOnline() {
return true;
}

@Override
public Parameters<String> getData() {
return LocalServiceScope.this.data;
}

}

public LocalServiceScope(Class<? extends KlabService> serviceClass,
BiConsumer<Scope, Message>... listeners) {
super(listeners);
this.serviceClass = serviceClass;
}

private Parameters<String> data = Parameters.create();
private Identity serviceIdentity;
private Class<? extends KlabService> serviceClass;

@Override
public Parameters<String> getData() {
return data;
}

@Override
public boolean isLocal() {
return true;
}

@Override
public boolean isExclusive() {
return false;
}

@Override
public boolean isDedicated() {
return true;
}

@Override
public Status getStatus() {
return status;
}

@Override
public <T extends KlabService> Collection<T> getServices(Class<T> serviceClass) {
// TODO if a service resolver is available to the service, that should be used.
return Collections.singleton(getService(serviceClass));
}

@Override
public Identity getIdentity() {
if (this.serviceIdentity != null) {
this.serviceIdentity = new LocalService(getService(this.serviceClass));
}
return this.serviceIdentity;
}

@Override
public void setStatus(Status status) {
this.status = status;
}

@Override
public void setData(String key, Object value) {
this.data.put(key, value);
}

}
Loading

0 comments on commit 22ccc35

Please sign in to comment.