Skip to content

Commit

Permalink
add git props
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhi.lyz committed May 13, 2021
1 parent e381cde commit 28864cf
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
23 changes: 23 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,29 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<includeOnlyProperties>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
</includeOnlyProperties>
<commitIdGenerationMode>full</commitIdGenerationMode>
</configuration>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.alipay.sofa.registry.server.data.change.DataChangeEventCenter;
import com.alipay.sofa.registry.server.data.lease.SessionLeaseManager;
import com.alipay.sofa.registry.server.data.slot.SlotManager;
import com.alipay.sofa.registry.server.shared.env.ServerEnv;
import com.alipay.sofa.registry.server.shared.meta.MetaServerService;
import com.alipay.sofa.registry.server.shared.remoting.AbstractServerHandler;
import com.github.rholder.retry.Retryer;
Expand Down Expand Up @@ -118,7 +119,7 @@ public boolean apply(Boolean input) {
public void start() {
try {
LOGGER.info("begin start server");

LOGGER.info("release properties: {}", ServerEnv.getReleaseProps());
LOGGER.info("the configuration items are as follows: " + dataServerConfig.toString());

ReporterUtils.enablePrometheusDefaultExports();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.alipay.sofa.registry.server.meta.bootstrap.config.MetaServerConfig;
import com.alipay.sofa.registry.server.meta.remoting.meta.MetaNodeExchange;
import com.alipay.sofa.registry.server.meta.remoting.meta.MetaServerRenewService;
import com.alipay.sofa.registry.server.shared.env.ServerEnv;
import com.alipay.sofa.registry.server.shared.remoting.AbstractServerHandler;
import com.alipay.sofa.registry.store.api.elector.LeaderElector;
import com.github.rholder.retry.Retryer;
Expand Down Expand Up @@ -118,6 +119,7 @@ public boolean apply(Boolean input) {
/** Do initialized. */
public void start() {
try {
LOGGER.info("release properties: {}", ServerEnv.getReleaseProps());
LOGGER.info("the configuration items are as follows: " + metaServerConfig.toString());
ReporterUtils.enablePrometheusDefaultExports();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public boolean apply(Boolean input) {
/** Do initialized. */
public void start() {
try {
LOGGER.info("release properties: {}", ServerEnv.getReleaseProps());
LOGGER.info("the configuration items are as follows: " + sessionServerConfig.toString());

initEnvironment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@
package com.alipay.sofa.registry.server.shared.env;

import com.alipay.sofa.registry.common.model.ProcessId;
import com.alipay.sofa.registry.log.Logger;
import com.alipay.sofa.registry.log.LoggerFactory;
import com.alipay.sofa.registry.net.NetUtil;
import com.alipay.sofa.registry.util.ParaCheckUtil;
import java.util.Collection;
import java.util.Map;
import java.util.Random;
import java.io.InputStream;
import java.util.*;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;

/**
* @author yuzhi.lyz
* @version v 0.1 2020-11-28 15:25 yuzhi.lyz Exp $
*/
public final class ServerEnv {
private static final Logger LOGGER = LoggerFactory.getLogger(ServerEnv.class);

private ServerEnv() {}

private static final String GIT_PROPS_FILE = "git.properties";
public static final String IP = NetUtil.getLocalAddress().getHostAddress();
public static final int PID = getPID();
public static final ProcessId PROCESS_ID = createProcessId();
Expand Down Expand Up @@ -70,4 +75,22 @@ public static Collection<String> getMetaAddresses(
}
return addresses;
}

public static Map<String, Object> getReleaseProps() {
InputStream inputStream = ServerEnv.class.getClassLoader().getResourceAsStream(GIT_PROPS_FILE);
Properties properties = new Properties();
if (inputStream != null) {
try {
properties.load(inputStream);
} catch (Throwable e) {
LOGGER.warn("failed to load release props file");
} finally {
IOUtils.closeQuietly(inputStream);
}
} else {
LOGGER.warn(
"release props file not found:{}", ServerEnv.class.getClassLoader().getResource("/"));
}
return new TreeMap<String, Object>((Map) properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ public void testMetas() {
Collection<String> ret = ServerEnv.getMetaAddresses(m, "localDc");
Assert.assertEquals(ret, meta);
}

@Test
public void testRelease() {
Map<String, Object> m = ServerEnv.getReleaseProps();
Assert.assertFalse(m.toString(), m.isEmpty());
System.out.println(m);
}
}

0 comments on commit 28864cf

Please sign in to comment.