Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,17 @@
import java.net.URL;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

import org.integratedmodelling.klab.api.authentication.ResourcePrivileges;
import org.integratedmodelling.klab.api.collections.Identifier;
import org.integratedmodelling.klab.api.data.*;
import org.integratedmodelling.klab.api.digitaltwin.impl.ConfigurationBuilder;
import org.integratedmodelling.klab.api.exceptions.KlabIllegalArgumentException;
import org.integratedmodelling.klab.api.exceptions.KlabIllegalStateException;
import org.integratedmodelling.klab.api.exceptions.KlabValidationException;
import org.integratedmodelling.klab.api.geometry.Geometry;
import org.integratedmodelling.klab.api.knowledge.Observable;
import org.integratedmodelling.klab.api.knowledge.SemanticType;
import org.integratedmodelling.klab.api.knowledge.Urn;
import org.integratedmodelling.klab.api.knowledge.observation.Observation;
import org.integratedmodelling.klab.api.knowledge.observation.impl.ObservationImpl;
import org.integratedmodelling.klab.api.knowledge.observation.scale.time.TimeInstant;
import org.integratedmodelling.klab.api.lang.Quantity;
import org.integratedmodelling.klab.api.lang.ServiceCall;
import org.integratedmodelling.klab.api.lang.kim.KimConcept;
import org.integratedmodelling.klab.api.lang.kim.KimModel;
import org.integratedmodelling.klab.api.lang.kim.KimObservable;
import org.integratedmodelling.klab.api.lang.kim.KimSymbolDefinition;
import org.integratedmodelling.klab.api.provenance.Activity;
import org.integratedmodelling.klab.api.provenance.Provenance;
import org.integratedmodelling.klab.api.scope.*;
import org.integratedmodelling.klab.api.services.Reasoner;
import org.integratedmodelling.klab.api.services.RuntimeService;
import org.integratedmodelling.klab.api.services.runtime.Dataflow;
import org.integratedmodelling.klab.api.services.runtime.Message;
import org.integratedmodelling.klab.api.services.runtime.Notification;
Expand Down Expand Up @@ -116,7 +97,7 @@ interface Configuration {
ResourcePrivileges getAccessRights();

/**
* These may be present when the configuration is the return value of a connect call.
* These describe any error, warning or info conditions relative to the digital twin.
*
* @return
*/
Expand Down Expand Up @@ -146,6 +127,15 @@ interface Configuration {
*/
String getId();

/**
* This is used to flag a failure in the creation of a digital twin or the connection. If true,
* the ID may be null and should not be used even if not. Notifications should contain at least
* one error if this returns true.
*
* @return
*/
boolean isEmpty();

@Deprecated
boolean isCreateWhenAbsent();

Expand Down Expand Up @@ -173,6 +163,16 @@ static Configuration create(URL url, UserScope scope) {
return new ConfigurationBuilder(url, scope).build();
}

static Configuration empty(Notification... notifications) {
var ret = new ConfigurationBuilder().empty();
if (notifications != null) {
for (var n : notifications) {
ret.withNotification(n);
}
}
return ret.build();
}

static ConfigurationBuilder builder() {
return new ConfigurationBuilder();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package org.integratedmodelling.klab.api.digitaltwin.impl;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.integratedmodelling.klab.api.Klab;
import org.integratedmodelling.klab.api.ServicesAPI;
import org.integratedmodelling.klab.api.authentication.ResourcePrivileges;
import org.integratedmodelling.klab.api.digitaltwin.DigitalTwin;
import org.integratedmodelling.klab.api.knowledge.observation.Observation;
import org.integratedmodelling.klab.api.scope.Persistence;
import org.integratedmodelling.klab.api.scope.Scope;
import org.integratedmodelling.klab.api.scope.UserScope;
import org.integratedmodelling.klab.api.services.runtime.Notification;
import org.integratedmodelling.klab.api.utils.Utils;
import org.integratedmodelling.klab.api.view.UIReactor;
import org.integratedmodelling.klab.api.view.modeler.views.controllers.AuthenticationViewController;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class ConfigurationBuilder {
private ResourcePrivileges accessRights;
Expand All @@ -26,11 +24,13 @@ public class ConfigurationBuilder {
private TimeUnit timeoutUnit;
private URL url;
private URL serverUrl;
private List<Notification> notifications = new ArrayList<>();
private final List<Notification> notifications = new ArrayList<>();
private boolean createWhenAbsent;
private String serviceId;
private String description;
private String owner;
private Observation observer;
private boolean empty;

public ConfigurationBuilder() {}

Expand All @@ -46,6 +46,8 @@ public ConfigurationBuilder(DigitalTwin.Configuration configuration) {
this.notifications.addAll(configuration.getNotifications());
this.createWhenAbsent = configuration.isCreateWhenAbsent();
this.serviceId = configuration.getServiceId();
this.observer = configuration.getObserver();
this.empty = configuration.isEmpty();
}

/**
Expand Down Expand Up @@ -118,6 +120,11 @@ public ConfigurationBuilder owner(String owner) {
return this;
}

public ConfigurationBuilder empty() {
this.empty = true;
return this;
}

public ConfigurationBuilder createWhenAbsent(boolean b) {
this.createWhenAbsent = b;
return this;
Expand Down Expand Up @@ -159,6 +166,11 @@ public ConfigurationBuilder timeout(long timeout, TimeUnit timeoutUnit) {
return this;
}

public ConfigurationBuilder observer(Observation observer) {
this.observer = observer;
return this;
}

public DigitalTwin.Configuration build() {
return new ConfigurationImpl(
accessRights,
Expand All @@ -173,6 +185,8 @@ public DigitalTwin.Configuration build() {
this.createWhenAbsent,
this.serviceId,
this.description,
this.owner);
this.owner,
this.empty,
this.observer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ConfigurationImpl implements DigitalTwin.Configuration {
private Observation observer;
private Data.ShardingStrategy shardingStrategy = new Data.ShardingStrategy();
private String owner;
private boolean empty;

// for the object mapper, do not remove
ConfigurationImpl() {}
Expand All @@ -51,7 +52,9 @@ public class ConfigurationImpl implements DigitalTwin.Configuration {
boolean createWhenAbsent,
String serviceId,
String description,
String owner) {
String owner,
boolean empty,
Observation observer) {
this.accessRights = accessRights;
this.persistence = persistence;
this.name = name;
Expand All @@ -65,6 +68,8 @@ public class ConfigurationImpl implements DigitalTwin.Configuration {
this.serviceId = serviceId;
this.description = description;
this.owner = owner;
this.empty = empty;
this.observer = observer;
}

@Override
Expand Down Expand Up @@ -106,6 +111,15 @@ public String getId() {
return id;
}

@Override
public boolean isEmpty() {
return empty;
}

public void setEmpty(boolean empty) {
this.empty = empty;
}

@Override
public DigitalTwin.Configuration validate(Scope scope) throws KlabValidationException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.integratedmodelling.klab.api.configuration.Setting;
import org.integratedmodelling.klab.api.configuration.Settings;
import org.integratedmodelling.klab.api.data.Metadata;
import org.integratedmodelling.klab.api.digitaltwin.DigitalTwin;
import org.integratedmodelling.klab.api.digitaltwin.Scheduler;
import org.integratedmodelling.klab.api.engine.Engine;
import org.integratedmodelling.klab.api.exceptions.KlabIllegalArgumentException;
Expand Down Expand Up @@ -395,18 +396,21 @@ String declareSessionScope(
* accessible to the resulting scope. If the service is not a runtime, the request must come from
* another service and the scope should be instrumented as necessary for its purposes.
*
* <p>FIXME this must return a {@link
* org.integratedmodelling.klab.api.digitaltwin.DigitalTwin.Configuration} so that we know the ID
* along with any observer geometry and other configuration when the scope already exists.
* <p>The return value is the {@link
* org.integratedmodelling.klab.api.digitaltwin.DigitalTwin.Configuration} that describes the
* scope. Much of its content will be the same as submitted, but along with the ID (or an empty()
* configuration in case of failure) we can also access the current observer geometry, any
* notifications and advisories, and other configuration of scopes that already existed.
*
* @param contextScope a client scope that should record the ID for future communication. If the
* ID is null, the call has failed.
* @param sessionScope used to set up federated behavior
* @param userScope used to establish the agent making changes (same as sessionScope's unless
* federated)
* @return the ID of the new context scope created at server side, or null in case of failure.
* @return the known configuration for the digital twin, including (if successful) the ID of the
* new context scope created at server side, or an empty configuration in case of failure.
*/
String declareContextScope(
DigitalTwin.Configuration declareContextScope(
ContextScope contextScope, SessionScope sessionScope, UserScope userScope);

/**
Comment thread
fvilla marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Predicate;

import org.integratedmodelling.common.authentication.scope.AbstractServiceDelegatingScope;
import org.integratedmodelling.common.authentication.scope.MessagingChannelImpl;
import org.integratedmodelling.common.logging.Logging;
Expand Down Expand Up @@ -175,7 +174,7 @@ public String declareSessionScope(
}

@Override
public String declareContextScope(
public DigitalTwin.Configuration declareContextScope(
ContextScope contextScope, SessionScope sessionScope, UserScope userScope) {

ScopeRequest request = new ScopeRequest();
Expand All @@ -188,18 +187,22 @@ public String declareContextScope(
.toList());

try {
var scopeId =
client.withScope(sessionScope).post(ServicesAPI.CREATE_CONTEXT, request, String.class);
if (scopeId != null) {
setupMessaging(contextScope, sessionScope, scopeId);
// give the server some time to set up the context and inform the other services
// Thread.sleep(1000);
var configuration =
client
.withScope(sessionScope)
.post(ServicesAPI.CREATE_CONTEXT, request, DigitalTwin.Configuration.class);
if (configuration != null && !configuration.isEmpty()) {
setupMessaging(contextScope, sessionScope, configuration.getId());
}
return scopeId;
return configuration == null
? DigitalTwin.Configuration.empty(
Notification.error("No valid return value from server at context creation"))
: configuration;

} catch (Throwable t) {
Logging.INSTANCE.error(this.serviceName() + " failed to declare context scope", t);
return DigitalTwin.Configuration.empty(
Notification.error(this.serviceName() + " failed to declare context scope", t));
}
return null;
}

private String setupMessaging(SessionScope sessionScope, UserScope userScope, String scopeId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.integratedmodelling.common.utils.Utils;
import org.integratedmodelling.klab.api.data.Data;
import org.integratedmodelling.klab.api.data.KnowledgeGraph;
import org.integratedmodelling.klab.api.data.Metadata;
import org.integratedmodelling.klab.api.data.RuntimeAsset;
import org.integratedmodelling.klab.api.digitaltwin.DigitalTwin;
import org.integratedmodelling.klab.api.digitaltwin.GraphModel;
Expand All @@ -16,7 +15,6 @@
import org.integratedmodelling.klab.api.identities.Federation;
import org.integratedmodelling.klab.api.knowledge.Observable;
import org.integratedmodelling.klab.api.knowledge.SemanticType;
import org.integratedmodelling.klab.api.knowledge.Semantics;
import org.integratedmodelling.klab.api.knowledge.observation.Observation;
import org.integratedmodelling.klab.api.knowledge.observation.impl.ObservationBuilderImpl;
import org.integratedmodelling.klab.api.knowledge.observation.impl.ObservationImpl;
Expand Down Expand Up @@ -135,6 +133,7 @@ public void setId(String id) {
super.setId(id);
if (this.configuration instanceof ConfigurationImpl configurationImpl) {
configurationImpl.setId(id);
configurationImpl.setUrl(Utils.URLs.newURL(runtimeService.getUrl() + "/dt/" + id));
}
}

Expand Down Expand Up @@ -470,9 +469,19 @@ public String getTransactionId() {

public void resolveDefaultObserver() {

if (getFederation() != null
&& getFederation().getId().equals(Federation.LOCAL_FEDERATION_ID)) {
// TODO
}
// TODO
}
Comment on lines 470 to +477
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 resolveDefaultObserver is entirely unimplemented

Both branches of this method are empty // TODO stubs, meaning the "create-default-observer" feature that this branch is named for is never actually invoked. Any caller that expects the method to hydrate or apply the observer field from the DigitalTwin.Configuration will silently receive an uninitialized observer. If this is intentional placeholder work, a // TODO on the feature-level tracking ticket (or a clearly-disabled call site) would prevent future confusion.



if (getFederation() != null && getFederation().getId().equals(Federation.LOCAL_FEDERATION_ID)) {
public void setFromConfiguration(DigitalTwin.Configuration configuration) {
if (configuration.isEmpty()) {
setEmpty(true);
} else {
setId(configuration.getId());
}
this.configuration.getNotifications().addAll(configuration.getNotifications());
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.integratedmodelling.common.services.client.scope;

import java.net.URL;
import java.util.Collection;
import java.util.List;
import org.integratedmodelling.klab.api.digitaltwin.DigitalTwin;
import org.integratedmodelling.klab.api.exceptions.KlabIllegalStateException;
import org.integratedmodelling.klab.api.exceptions.KlabInternalErrorException;
Expand All @@ -10,11 +13,6 @@
import org.integratedmodelling.klab.api.services.KlabService;
import org.integratedmodelling.klab.api.services.RuntimeService;

import java.net.URL;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;

/** Client-side session scope */
public class ClientSessionScope extends ClientUserScope implements SessionScope {

Expand Down Expand Up @@ -48,7 +46,7 @@ public <T extends KlabService> T getService(Class<T> serviceClass) {
return super.getService(serviceClass);
}

/**
/**
* Use to pre-define the ID when necessary.
*
* @param id
Expand Down Expand Up @@ -100,9 +98,8 @@ public ContextScope createContext(DigitalTwin.Configuration configuration) {
*/
var ret = new ClientContextScope(this, runtime, configuration.validate(this));
var id = runtime.declareContextScope(ret, this, userScope);

if (id != null) {
ret.setId(id);
ret.setFromConfiguration(id);
if (!id.isEmpty()) {
ClientScopeManager.INSTANCE.register(ret);
Comment thread
greptile-apps[bot] marked this conversation as resolved.
}

Expand Down
Loading
Loading