Skip to content

Commit

Permalink
pir register service inforamtion
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Nov 7, 2024
1 parent 6a56078 commit fc142a8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class WeDPRCommonConfig {
WeDPRConfig.apply("wedpr.worker.api.method.submit", "submit");

private static String SHELL_CODE_CONNECTOR = " && ";
private static String serverListenPort;

@SneakyThrows
public static String getAgency() {
Expand All @@ -79,7 +80,7 @@ public static String getAgency() {
@SneakyThrows
public static String getAdminAgency() {
if (StringUtils.isBlank(ADMIN_AGENCY)) {
throw new WeDPRException("Invalid emtpy agency!");
throw new WeDPRException("Invalid emtpy admin agency!");
}
return ADMIN_AGENCY;
}
Expand Down Expand Up @@ -156,4 +157,12 @@ public static String getWedprWorkerApiPath() {
public static String getWedprWorkerSubmitTaskMethod() {
return WEDPR_WORKER_SUBMIT_TASK_METHOD;
}

public static String getServerListenPort() {
return serverListenPort;
}

public static void setServerListenPort(String serverListenPort) {
serverListenPort = serverListenPort;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,7 @@ public class Constant {
// the pir related fields
public static final String PIR_ID_FIELD_NAME = "pir_sys_id";
public static final String PIR_ID_HASH_FIELD_NAME = "pir_sys_id_hash";

//// the serviceType
public static final String PIR_SERVICE_TYPE = "PIR";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package com.webank.wedpr.components.initializer;

import com.webank.wedpr.common.config.WeDPRCommonConfig;
import com.webank.wedpr.common.config.WeDPRConfig;
import com.webank.wedpr.common.utils.WeDPRException;
import java.io.InputStream;
Expand All @@ -33,6 +34,7 @@
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;

@SpringBootApplication
@ComponentScan(basePackages = {"com.webank"})
Expand All @@ -42,6 +44,7 @@ public class WeDPRApplication extends SpringBootServletInitializer {

protected static ServiceInfo serviceInfo;
protected static ConfigurableApplicationContext applicationContext;
private static String serverListenPort;

public static void main(String[] args, String serviceName) throws Exception {
final SpringApplication application = new SpringApplication(WeDPRApplication.class);
Expand All @@ -53,6 +56,11 @@ public void onApplicationEvent(ApplicationPreparedEvent event) {
if (applicationContext == null) {
applicationContext = event.getApplicationContext();
}
Environment environment = applicationContext.getEnvironment();
serverListenPort = environment.getProperty("server.port");
logger.info(
"init WeDPRApplication application, listen port: {}",
serverListenPort);
initWeDPRApplication(serviceName);
logger.info("init WeDPRApplication application success");
}
Expand Down Expand Up @@ -82,7 +90,8 @@ protected static void initWeDPRApplication(String serviceName) {
}
// load config
loadConfig(serviceInfo.getConfigFile());

// Note: must load WeDPRCommonConfig after config file loaded
WeDPRCommonConfig.setServerListenPort(serverListenPort);
logger.info("initWeDPRApplication for {} success", appName);
} catch (Exception e) {
logger.error("initWeDPRApplication failed, error: ", e);
Expand Down
2 changes: 0 additions & 2 deletions wedpr-components/key-generator/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Apply the java-library plugin to add support for Java Library
plugins {
id 'org.springframework.boot' version '2.3.12.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ private void doReport() {
reportProjectInfo(adminAgency);
reportJobInfo(adminAgency);
reportJobDatasteRelationInfo(adminAgency);
// reportSysConfig(adminAgency);
} catch (Exception e) {
log.warn("report error", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
package com.webank.wedpr.components.task.plugin.pir.service.impl;

import com.webank.wedpr.common.config.WeDPRCommonConfig;
import com.webank.wedpr.common.utils.Constant;
import com.webank.wedpr.common.utils.ThreadPoolService;
import com.webank.wedpr.common.utils.WeDPRException;
import com.webank.wedpr.common.utils.WeDPRResponse;
import com.webank.wedpr.common.utils.*;
import com.webank.wedpr.components.api.credential.core.CredentialVerifier;
import com.webank.wedpr.components.api.credential.core.impl.CredentialVerifierImpl;
import com.webank.wedpr.components.db.mapper.dataset.mapper.DatasetMapper;
Expand Down Expand Up @@ -49,6 +46,7 @@
import com.webank.wedpr.components.task.plugin.pir.service.PirService;
import com.webank.wedpr.components.task.plugin.pir.transport.PirTopicSubscriber;
import com.webank.wedpr.components.task.plugin.pir.transport.impl.PirTopicSubscriberImpl;
import com.webank.wedpr.sdk.jni.transport.TransportConfig;
import com.webank.wedpr.sdk.jni.transport.WeDPRTransport;
import java.util.List;
import javax.annotation.PostConstruct;
Expand Down Expand Up @@ -105,6 +103,15 @@ public void init() throws Exception {
this.pirTopicSubscriber =
new PirTopicSubscriberImpl(
weDPRTransport, new CredentialVerifierImpl(null), pirServiceHook);
// get the access entrypoint
TransportConfig transportConfig = weDPRTransport.getTransportConfig();
String accessEntryPoint =
Common.getUrl(
transportConfig.getSelfEndPoint().getHostIP()
+ ":"
+ WeDPRCommonConfig.getServerListenPort());
this.weDPRTransport.registerService(Constant.PIR_SERVICE_TYPE, accessEntryPoint);
logger.info("PirServiceImpl, register service, accessEntryPoint: {}", accessEntryPoint);
registerPublishedServices();
this.serviceAuthVerifier = new ServiceAuthVerifierImpl(serviceAuthMapper);
}
Expand Down

0 comments on commit fc142a8

Please sign in to comment.