Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #4781]management life cycle #4783

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -22,32 +22,26 @@
import org.apache.eventmesh.api.exception.AclException;
import org.apache.eventmesh.api.meta.bo.EventMeshAppSubTopicInfo;
import org.apache.eventmesh.api.meta.bo.EventMeshServicePubTopicInfo;
import org.apache.eventmesh.common.config.CommonConfiguration;
import org.apache.eventmesh.common.protocol.tcp.UserAgent;
import org.apache.eventmesh.runtime.lifecircle.EventMeshSwitchableComponent;
import org.apache.eventmesh.spi.EventMeshExtensionFactory;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Acl {
public class Acl extends EventMeshSwitchableComponent {

private static final Map<String, Acl> ACL_CACHE = new HashMap<>(16);

private AclService aclService;

private final AtomicBoolean inited = new AtomicBoolean(false);

private final AtomicBoolean started = new AtomicBoolean(false);

private final AtomicBoolean shutdown = new AtomicBoolean(false);

private Acl() {

}

public static Acl getInstance(String aclPluginType) {
Expand All @@ -67,26 +61,23 @@ private static Acl aclBuilder(String aclPluginType) {
return acl;
}

public void init() throws AclException {
if (!inited.compareAndSet(false, true)) {
return;
}
@Override
protected boolean shouldTurn(CommonConfiguration configuration) {
return configuration.isEventMeshServerSecurityEnable();
}

@Override
protected void componentInit() throws AclException {
aclService.init();
}

public void start() throws AclException {
if (!started.compareAndSet(false, true)) {
return;
}
@Override
protected void componentStart() throws AclException {
aclService.start();
}

public void shutdown() throws AclException {
inited.compareAndSet(true, false);
started.compareAndSet(true, false);
if (!shutdown.compareAndSet(false, true)) {
return;
}
@Override
protected void componentStop() throws AclException {
aclService.shutdown();
}

Expand All @@ -112,7 +103,7 @@ public void doAclCheckInHttpSend(String remoteAddr, String user, String pass, St
}

public void doAclCheckInHttpSend(String remoteAddr, String user, String pass, String subsystem, String topic,
String requestURI) throws AclException {
String requestURI) throws AclException {
aclService.doAclCheckInSend(buildHttpAclProperties(remoteAddr, user, pass, subsystem, topic, requestURI));
}

Expand All @@ -122,17 +113,17 @@ public void doAclCheckInHttpSend(String remoteAddr, String token, String subsyst
}

public void doAclCheckInHttpReceive(String remoteAddr, String user, String pass, String subsystem, String topic,
int requestCode) throws AclException {
int requestCode) throws AclException {
aclService.doAclCheckInReceive(buildHttpAclProperties(remoteAddr, user, pass, subsystem, topic, requestCode));
}

public void doAclCheckInHttpReceive(String remoteAddr, String user, String pass, String subsystem, String topic,
String requestURI) throws AclException {
String requestURI) throws AclException {
aclService.doAclCheckInReceive(buildHttpAclProperties(remoteAddr, user, pass, subsystem, topic, requestURI));
}

public void doAclCheckInTcpReceive(String remoteAddr, String token, String subsystem, String topic,
String requestURI, Object obj) throws AclException {
String requestURI, Object obj) throws AclException {
aclService.doAclCheckInReceive(buildTcpAclProperties(remoteAddr, token, subsystem, topic, requestURI, obj));
}

Expand All @@ -141,7 +132,7 @@ public void doAclCheckInTcpReceive(String remoteAddr, UserAgent userAgent, Strin
}

public void doAclCheckInHttpHeartbeat(String remoteAddr, String user, String pass, String subsystem, String topic,
int requestCode) throws AclException {
int requestCode) throws AclException {
aclService.doAclCheckInHeartbeat(buildHttpAclProperties(remoteAddr, user, pass, subsystem, topic, requestCode));
}

Expand Down Expand Up @@ -236,4 +227,5 @@ private AclProperties buildTcpAclProperties(String remoteAddr, String token, Str
return aclProperties;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,32 @@

package org.apache.eventmesh.runtime.boot;

public class EventMeshAdminBootstrap implements EventMeshBootstrap {
import org.apache.eventmesh.common.config.CommonConfiguration;
import org.apache.eventmesh.runtime.lifecircle.EventMeshSwitchableComponent;

import java.util.List;

public class EventMeshAdminBootstrap extends EventMeshSwitchableComponent implements EventMeshBootstrap {

private EventMeshAdminServer eventMeshAdminServer;

private EventMeshServer eventMeshServer;

// http grpc tcp
private final int exposeServerChannelCount = 3;

public EventMeshAdminBootstrap(EventMeshServer eventMeshServer) {
this.eventMeshServer = eventMeshServer;
}

@Override
public void init() throws Exception {
protected boolean shouldTurn(CommonConfiguration configuration) {
final List<String> provideServerProtocols = configuration.getEventMeshProvideServerProtocols();
return !(provideServerProtocols.size() == exposeServerChannelCount);
}

@Override
protected void componentInit() throws Exception {
if (eventMeshServer != null) {
eventMeshAdminServer = new EventMeshAdminServer(eventMeshServer);
eventMeshAdminServer.init();
Expand All @@ -37,15 +51,15 @@ public void init() throws Exception {
}

@Override
public void start() throws Exception {
protected void componentStart() throws Exception {
if (eventMeshAdminServer != null) {
eventMeshAdminServer.start();
}

}

@Override
public void shutdown() throws Exception {
protected void componentStop() throws Exception {
if (eventMeshAdminServer != null) {
eventMeshAdminServer.shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import org.apache.eventmesh.common.config.ConfigService;
import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
import org.apache.eventmesh.runtime.configuration.EventMeshGrpcConfiguration;
import org.apache.eventmesh.runtime.lifecircle.EventMeshComponent;

public class EventMeshGrpcBootstrap implements EventMeshBootstrap {
public class EventMeshGrpcBootstrap extends EventMeshComponent implements EventMeshBootstrap {

private final EventMeshGrpcConfiguration eventMeshGrpcConfiguration;

Expand All @@ -40,7 +41,7 @@ public EventMeshGrpcBootstrap(final EventMeshServer eventMeshServer) {
}

@Override
public void init() throws Exception {
public void componentInit() throws Exception {
// server init
if (eventMeshGrpcConfiguration != null) {
eventMeshGrpcServer = new EventMeshGrpcServer(this.eventMeshServer, this.eventMeshGrpcConfiguration);
Expand All @@ -49,21 +50,21 @@ public void init() throws Exception {
}

@Override
public void start() throws Exception {
protected void componentStart() throws Exception {
// server start
if (eventMeshGrpcConfiguration != null) {
eventMeshGrpcServer.start();
}
}

@Override
public void shutdown() throws Exception {
protected void componentStop() throws Exception {
if (eventMeshGrpcConfiguration != null) {
eventMeshGrpcServer.shutdown();
}
}

public EventMeshGrpcServer getEventMeshGrpcServer() {
protected EventMeshGrpcServer getEventMeshGrpcServer() {
return eventMeshGrpcServer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import org.apache.eventmesh.common.config.ConfigService;
import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
import org.apache.eventmesh.runtime.configuration.EventMeshHTTPConfiguration;
import org.apache.eventmesh.runtime.lifecircle.EventMeshComponent;

public class EventMeshHttpBootstrap implements EventMeshBootstrap {
public class EventMeshHttpBootstrap extends EventMeshComponent implements EventMeshBootstrap {

private final EventMeshHTTPConfiguration eventMeshHttpConfiguration;

Expand All @@ -41,7 +42,7 @@ public EventMeshHttpBootstrap(final EventMeshServer eventMeshServer) {
}

@Override
public void init() throws Exception {
protected void componentInit() throws Exception {
// server init
if (eventMeshHttpConfiguration != null) {
eventMeshHttpServer = new EventMeshHTTPServer(eventMeshServer, eventMeshHttpConfiguration);
Expand All @@ -50,15 +51,15 @@ public void init() throws Exception {
}

@Override
public void start() throws Exception {
protected void componentStart() throws Exception {
// server start
if (eventMeshHttpServer != null) {
eventMeshHttpServer.start();
}
}

@Override
public void shutdown() throws Exception {
protected void componentStop() throws Exception {
// server shutdown
if (eventMeshHttpServer != null) {
eventMeshHttpServer.shutdown();
Expand Down
Loading
Loading