Skip to content

Commit

Permalink
OAP-120 Move oap-remote to a separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
nofateg authored Apr 11, 2024
1 parent 03fa8e4 commit 2bba967
Show file tree
Hide file tree
Showing 250 changed files with 3,827 additions and 3,675 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public void start() {
System.setProperty( "failedValue", "value that can fail config parsing" );
var modules = List.of(
url( "modules/m1.conf" ),
url( "modules/m2.json" ),
url( "modules/m3.yaml" )
url( "modules/m2.conf" ),
url( "modules/m3.conf" )
);

var kernel = new Kernel( modules );
Expand Down Expand Up @@ -159,9 +159,9 @@ public void disabled() {
try {
kernel.start( Map.of( "boot.main", "disabled" ) );

assertThat( kernel.<ServiceOne>service( "modules..s1" ) ).isPresent().get()
assertThat( kernel.<ServiceOne>service( "disabled.s1" ) ).isPresent().get()
.satisfies( s1 -> assertThat( s1.list ).isEmpty() );
assertThat( kernel.<ServiceOne>service( "modules..s2" ) ).isNotPresent();
assertThat( kernel.<ServiceOne>service( "disabled.s2" ) ).isNotPresent();
} finally {
kernel.stop();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
boot.main = m3
boot.main = m3

profiles = [profileOne]
services {
m2.ServiceTwo.parameters.j = ${a.b}
m1.ServiceOneP1.parameters.i2 = ${one.i2}
}
profiles = [profileOne]
services {
m2.ServiceTwo.parameters.j = ${a.b}
m1.ServiceOneP1.parameters.i2 = ${one.i2}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
{
name = disabled
services {
s1 {
implementation = oap.application.ServiceOne
parameters {
i = 1
list = [
modules.this.s2
]
}
dependsOn = [s2]
name = disabled
services {
s1 {
implementation = oap.application.ServiceOne
parameters {
i = 1
list = [
<modules.this.s2>
]
}
s2 {
implementation = oap.application.ServiceOne
profile = disabled
parameters {
i = 2
}
dependsOn = [s2]
}
s2 {
implementation = oap.application.ServiceOne
profile = disabled
parameters {
i = 2
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name = m2
dependsOn = m1

services {
ServiceTwo {
implementation = oap.application.ServiceTwo
parameters {
j = 1
one = <modules.m1.ServiceOne>
}
listen {
some = <modules.m1.ServiceOne>
},
supervision.supervise = true
}
ServiceScheduled {
implementation = oap.application.ServiceScheduled
supervision {
schedule = true
delay = 1s
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name = m3
dependsOn = [
m1
m2
]
services {
ServiceDepsList {
implementation = oap.application.ServiceDepsList
parameters {
deps = [
<modules.m1.ServiceOne>
<modules.m2.ServiceTwo>
]
}
}
}

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions oap-application/oap-application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
<artifactId>oap-http</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>oap</groupId>
<artifactId>oap-remote</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>oap</groupId>
<artifactId>oap-application-cli</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import oap.application.module.Reference;
import oap.application.module.Service;
import oap.application.module.ServiceExt;
import oap.application.remote.RemoteInvocationHandler;
import oap.application.supervision.Supervisor;
import oap.json.Binder;
import oap.reflect.Reflect;
Expand Down Expand Up @@ -224,10 +223,21 @@ private ServiceInitializationTree instantiateServices( ModuleItemTree map ) thro
var implName = serviceItem.serviceName;
log.trace( "instantiating {}.{} as {} class:{} ...", moduleName, implName, service.name, service.implementation );
try {
Object instance = null;

var reflect = Reflect.reflect( service.implementation, Module.coersions );
Object instance;
if( !service.isRemoteService() ) {
var parametersWithoutLinks = fixLinksForConstructor( this, moduleItem, retModules, service );

for( var ext : service.ext.values() ) {
if( ext instanceof ServiceKernelListener skl ) {
instance = skl.newInstance( this, retModules, serviceItem, reflect );
if( instance != null ) {
break;
}
}
}

if( instance == null ) {
var parametersWithoutLinks = fixLinksForConstructor( this, serviceItem.moduleItem, retModules, service );

var p = new LinkedHashMap<String, Object>();
p.putAll( parametersWithoutLinks.serviceReferenceParameters );
Expand All @@ -236,13 +246,12 @@ private ServiceInitializationTree instantiateServices( ModuleItemTree map ) thro
instance = reflect.newInstance( p, parametersWithoutLinks.serviceReferenceParameters.keySet() );

service.parameters.putAll( parametersWithoutLinks.serviceReferenceParameters );
} else {
instance = RemoteInvocationHandler.proxy( serviceItem.getModuleName() + ":" + service.name, service.remote, reflect.underlying );
}

retModules.put( serviceItem, new ServiceInitialization( implName, instance, moduleItem, service, reflect ) );
} catch( Exception e ) {
log.error( "Cannot create/initialize service name = {}.{}, remote = {}, profiles = {}, class: {}",
moduleName, implName, service.remote, service.profiles, service.implementation );
log.error( "Cannot create/initialize service name = {}.{} profiles = {}, class: {}",
moduleName, implName, service.profiles, service.implementation );
throw new ApplicationException( e );
}
}
Expand Down Expand Up @@ -417,7 +426,7 @@ private <T> Optional<T> service( Reference reference ) {

public <T> Optional<T> service( String reference ) {
var ref = ServiceKernelCommand.INSTANCE.reference(
reference.startsWith( "modules." ) ? reference : "modules." + reference, null );
reference.startsWith( "<modules." ) ? reference : "<modules." + reference + ">", null );
return service( ref );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static ModuleItemTree init( LinkedHashSet<Kernel.ModuleWithLocation> modu
validateImplementation( map );
sort( map );
removeDisabled( map );
validateRemoting( map );
validateServices( map );

return map;
}
Expand Down Expand Up @@ -274,21 +274,25 @@ private static void loadOnlyMainModuleAndDependsOn( ModuleItemTree modules,
}
}

private static void validateRemoting( ModuleItemTree map ) throws ApplicationException {
var invalidRemoting = new ArrayList<String>();
private static void validateServices( ModuleItemTree map ) throws ApplicationException {
var errors = new ArrayList<String>();

for( var moduleItem : map.values() ) {
for( var serviceItem : moduleItem.services.values() ) {
if( !serviceItem.service.isRemoteService() ) continue;

if( serviceItem.service.remote.url == null )
invalidRemoting.add( moduleItem.getName() + ":" + serviceItem.serviceName );
for( var ext : serviceItem.service.ext.values() ) {
if( ext instanceof ServiceKernelListener skl ) {
errors.addAll( skl.validate( serviceItem ) );
}
}
}
}

if( !invalidRemoting.isEmpty() ) {
log.error( "url == null, services " + invalidRemoting );
throw new ApplicationException( "remoting: url == null, services " + invalidRemoting );
if( !errors.isEmpty() ) {
for( var message : errors ) {
log.error( message );
}

throw new ApplicationException( "error: " + errors );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class ServiceKernelCommand extends AbstractKernelCommand<ServiceInitializ
public static final ServiceKernelCommand INSTANCE = new ServiceKernelCommand();

private ServiceKernelCommand() {
super( "^<?modules\\.([^.]*)\\.(.+)>?$" );
super( "^<modules\\.([^.]*)\\.(.+)>$" );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package oap.application;

import oap.reflect.Reflection;

import java.util.List;

public interface ServiceKernelListener {
Object newInstance( Kernel kernel,
ServiceInitializationTree retModules,
ModuleItem.ServiceItem serviceItem, Reflection reflect );

default List<String> validate( ModuleItem.ServiceItem serviceItem ) {
return List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import oap.application.remote.RemoteLocation;

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
Expand All @@ -52,7 +51,6 @@ public class Service {
public final LinkedHashMap<String, String> link = new LinkedHashMap<>();
public String implementation;
public String name;
public RemoteLocation remote;
@JsonIgnore
public LinkedHashMap<String, Object> ext = new LinkedHashMap<>();

Expand All @@ -66,11 +64,6 @@ public Map<String, Object> getUnknown() {
return ext;
}

@JsonIgnore
public boolean isRemoteService() {
return remote != null;
}

@SuppressWarnings( "unchecked" )
public <T> T getExt( String ext ) {
return ( T ) this.ext.get( ext );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package oap.application.supervision;

import lombok.extern.slf4j.Slf4j;
import oap.application.remote.RemoteInvocationException;
import oap.remote.RemoteInvocationException;
import oap.concurrent.scheduler.Scheduled;

@Slf4j
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<parent>
<groupId>oap</groupId>
<artifactId>oap</artifactId>
<artifactId>oap-formats-parent</artifactId>
<version>${oap.project.version}</version>
</parent>

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion oap-template/pom.xml → oap-formats/oap-template/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<parent>
<groupId>oap</groupId>
<artifactId>oap</artifactId>
<artifactId>oap-formats-parent</artifactId>
<version>${oap.project.version}</version>
</parent>

Expand Down
Loading

0 comments on commit 2bba967

Please sign in to comment.