mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-10 10:12:19 -06:00
chore: Minor format change
This commit is contained in:
parent
061d672774
commit
b6970fb247
@ -66,47 +66,48 @@ import io.onedev.server.util.init.InitStage;
|
|||||||
import io.onedev.server.util.init.ManualConfig;
|
import io.onedev.server.util.init.ManualConfig;
|
||||||
|
|
||||||
public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(OneDev.class);
|
private static final Logger logger = LoggerFactory.getLogger(OneDev.class);
|
||||||
|
|
||||||
private final Provider<JettyService> jettyLauncherProvider;
|
private final Provider<JettyService> jettyLauncherProvider;
|
||||||
|
|
||||||
private final SessionService sessionService;
|
private final SessionService sessionService;
|
||||||
|
|
||||||
private final DataService dataService;
|
private final DataService dataService;
|
||||||
|
|
||||||
private final Provider<ServerConfig> serverConfigProvider;
|
private final Provider<ServerConfig> serverConfigProvider;
|
||||||
|
|
||||||
private final ListenerRegistry listenerRegistry;
|
private final ListenerRegistry listenerRegistry;
|
||||||
|
|
||||||
private final TaskScheduler taskScheduler;
|
private final TaskScheduler taskScheduler;
|
||||||
|
|
||||||
private final ExecutorService executorService;
|
private final ExecutorService executorService;
|
||||||
|
|
||||||
private final ClusterService clusterService;
|
private final ClusterService clusterService;
|
||||||
|
|
||||||
private final SettingService settingService;
|
private final SettingService settingService;
|
||||||
|
|
||||||
private final IdService idService;
|
private final IdService idService;
|
||||||
|
|
||||||
private final SessionFactoryService sessionFactoryService;
|
private final SessionFactoryService sessionFactoryService;
|
||||||
|
|
||||||
private final Date bootDate = new Date();
|
private final Date bootDate = new Date();
|
||||||
|
|
||||||
private volatile InitStage initStage;
|
private volatile InitStage initStage;
|
||||||
|
|
||||||
private Class<?> wrapperManagerClass;
|
private Class<?> wrapperManagerClass;
|
||||||
|
|
||||||
private volatile Thread thread;
|
private volatile Thread thread;
|
||||||
|
|
||||||
// Some are injected via provider as instantiation might encounter problem during upgrade
|
// Some are injected via provider as instantiation might encounter problem
|
||||||
|
// during upgrade
|
||||||
@Inject
|
@Inject
|
||||||
public OneDev(Provider<JettyService> jettyLauncherProvider, TaskScheduler taskScheduler,
|
public OneDev(Provider<JettyService> jettyLauncherProvider, TaskScheduler taskScheduler,
|
||||||
SessionService sessionService, Provider<ServerConfig> serverConfigProvider,
|
SessionService sessionService, Provider<ServerConfig> serverConfigProvider,
|
||||||
DataService dataService, ExecutorService executorService,
|
DataService dataService, ExecutorService executorService,
|
||||||
ListenerRegistry listenerRegistry, ClusterService clusterService,
|
ListenerRegistry listenerRegistry, ClusterService clusterService,
|
||||||
IdService idService, SessionFactoryService sessionFactoryService,
|
IdService idService, SessionFactoryService sessionFactoryService,
|
||||||
SettingService settingService) {
|
SettingService settingService) {
|
||||||
this.jettyLauncherProvider = jettyLauncherProvider;
|
this.jettyLauncherProvider = jettyLauncherProvider;
|
||||||
this.taskScheduler = taskScheduler;
|
this.taskScheduler = taskScheduler;
|
||||||
this.sessionService = sessionService;
|
this.sessionService = sessionService;
|
||||||
@ -118,7 +119,7 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
this.idService = idService;
|
this.idService = idService;
|
||||||
this.sessionFactoryService = sessionFactoryService;
|
this.sessionFactoryService = sessionFactoryService;
|
||||||
this.settingService = settingService;
|
this.settingService = settingService;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
wrapperManagerClass = Class.forName("org.tanukisoftware.wrapper.WrapperManager");
|
wrapperManagerClass = Class.forName("org.tanukisoftware.wrapper.WrapperManager");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
@ -127,7 +128,7 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
|
|
||||||
initStage = new InitStage("Server is Starting...");
|
initStage = new InitStage("Server is Starting...");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
var maintenanceFile = getMaintenanceFile(Bootstrap.installDir);
|
var maintenanceFile = getMaintenanceFile(Bootstrap.installDir);
|
||||||
@ -139,18 +140,19 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SecurityUtils.bindAsSystem();
|
SecurityUtils.bindAsSystem();
|
||||||
|
|
||||||
System.setProperty("hsqldb.reconfig_logging", "false");
|
System.setProperty("hsqldb.reconfig_logging", "false");
|
||||||
System.setProperty("hsqldb.method_class_names", "java.lang.Math");
|
System.setProperty("hsqldb.method_class_names", "java.lang.Math");
|
||||||
|
|
||||||
clusterService.start();
|
clusterService.start();
|
||||||
sessionFactoryService.start();
|
sessionFactoryService.start();
|
||||||
|
|
||||||
var databasePopulated = clusterService.getHazelcastInstance().getCPSubsystem().getAtomicLong("databasePopulated");
|
var databasePopulated = clusterService.getHazelcastInstance().getCPSubsystem()
|
||||||
// Do not use database lock as schema update will commit transaction immediately
|
.getAtomicLong("databasePopulated");
|
||||||
// in MySQL
|
// Do not use database lock as schema update will commit transaction immediately
|
||||||
|
// in MySQL
|
||||||
clusterService.initWithLead(databasePopulated, () -> {
|
clusterService.initWithLead(databasePopulated, () -> {
|
||||||
try (var conn = dataService.openConnection()) {
|
try (var conn = dataService.openConnection()) {
|
||||||
callWithTransaction(conn, () -> {
|
callWithTransaction(conn, () -> {
|
||||||
@ -159,10 +161,10 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
});
|
});
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
};
|
}
|
||||||
return 1L;
|
return 1L;
|
||||||
});
|
});
|
||||||
|
|
||||||
idService.init();
|
idService.init();
|
||||||
|
|
||||||
sessionService.run(() -> listenerRegistry.post(new SystemStarting()));
|
sessionService.run(() -> listenerRegistry.post(new SystemStarting()));
|
||||||
@ -200,7 +202,7 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
}
|
}
|
||||||
if (thread == null)
|
if (thread == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
manualConfigs = checkData();
|
manualConfigs = checkData();
|
||||||
if (manualConfigs.isEmpty()) {
|
if (manualConfigs.isEmpty()) {
|
||||||
initStage = new InitStage("Please wait...");
|
initStage = new InitStage("Please wait...");
|
||||||
@ -210,7 +212,7 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var leadServer = clusterService.getLeaderServerAddress();
|
var leadServer = clusterService.getLeaderServerAddress();
|
||||||
if (!leadServer.equals(clusterService.getLocalServerAddress())) {
|
if (!leadServer.equals(clusterService.getLocalServerAddress())) {
|
||||||
logger.info("Syncing assets...");
|
logger.info("Syncing assets...");
|
||||||
@ -224,7 +226,7 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
|
|
||||||
try (Response response = builder.get()) {
|
try (Response response = builder.get()) {
|
||||||
checkStatus(response);
|
checkStatus(response);
|
||||||
try (InputStream is = response.readEntity(InputStream.class)) {
|
try (InputStream is = response.readEntity(InputStream.class)) {
|
||||||
TarUtils.untar(is, getAssetsDir(), false);
|
TarUtils.untar(is, getAssetsDir(), false);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -234,16 +236,16 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// workaround for issue https://bugs.eclipse.org/bugs/show_bug.cgi?id=566170
|
// workaround for issue https://bugs.eclipse.org/bugs/show_bug.cgi?id=566170
|
||||||
FileStoreAttributes.setBackground(true);
|
FileStoreAttributes.setBackground(true);
|
||||||
taskScheduler.start();
|
taskScheduler.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Sessional
|
@Sessional
|
||||||
@Override
|
@Override
|
||||||
public void postStart() {
|
public void postStart() {
|
||||||
if (thread == null)
|
if (thread == null)
|
||||||
return;
|
return;
|
||||||
SecurityUtils.bindAsSystem();
|
SecurityUtils.bindAsSystem();
|
||||||
initStage = null;
|
initStage = null;
|
||||||
@ -265,7 +267,7 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
} catch (ServerNotReadyException ignore) {
|
} catch (ServerNotReadyException ignore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ManualConfig> checkData() {
|
private List<ManualConfig> checkData() {
|
||||||
HazelcastInstance hazelcastInstance = clusterService.getHazelcastInstance();
|
HazelcastInstance hazelcastInstance = clusterService.getHazelcastInstance();
|
||||||
var lock = hazelcastInstance.getCPSubsystem().getLock("checkData");
|
var lock = hazelcastInstance.getCPSubsystem().getLock("checkData");
|
||||||
@ -307,11 +309,11 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getK8sService() {
|
public static String getK8sService() {
|
||||||
return System.getenv("k8s_service");
|
return System.getenv("k8s_service");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String guessServerUrl() {
|
public String guessServerUrl() {
|
||||||
String serviceHost = System.getenv("ONEDEV_SERVICE_HOST");
|
String serviceHost = System.getenv("ONEDEV_SERVICE_HOST");
|
||||||
if (serviceHost != null) {
|
if (serviceHost != null) {
|
||||||
@ -332,36 +334,38 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
return UrlUtils.toString(serverUrl);
|
return UrlUtils.toString(serverUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Url buildServerUrl(String host, String protocol, int port) {
|
|
||||||
Url serverUrl = new Url(StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
serverUrl.setHost(host);
|
private Url buildServerUrl(String host, String protocol, int port) {
|
||||||
serverUrl.setProtocol(protocol);
|
Url serverUrl = new Url(StandardCharsets.UTF_8);
|
||||||
serverUrl.setPort(port);
|
|
||||||
|
serverUrl.setHost(host);
|
||||||
|
serverUrl.setProtocol(protocol);
|
||||||
|
serverUrl.setPort(port);
|
||||||
|
|
||||||
return serverUrl;
|
return serverUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method can be called from different UI threads, so we clone initStage to
|
* This method can be called from different UI threads, so we clone initStage to
|
||||||
* make it thread-safe.
|
* make it thread-safe.
|
||||||
* <p>
|
* <p>
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
* cloned initStage, or <tt>null</tt> if system initialization is completed
|
* cloned initStage, or <tt>null</tt> if system initialization is
|
||||||
|
* completed
|
||||||
*/
|
*/
|
||||||
public @Nullable InitStage getInitStage() {
|
public @Nullable InitStage getInitStage() {
|
||||||
return initStage;
|
return initStage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReady() {
|
public boolean isReady() {
|
||||||
return initStage == null;
|
return initStage == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OneDev getInstance() {
|
public static OneDev getInstance() {
|
||||||
return AppLoader.getInstance(OneDev.class);
|
return AppLoader.getInstance(OneDev.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T getInstance(Class<T> type) {
|
public static <T> T getInstance(Class<T> type) {
|
||||||
return AppLoader.getInstance(type);
|
return AppLoader.getInstance(type);
|
||||||
}
|
}
|
||||||
@ -380,8 +384,8 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
|
|
||||||
public Object writeReplace() throws ObjectStreamException {
|
public Object writeReplace() throws ObjectStreamException {
|
||||||
return new ManagedSerializedForm(OneDev.class);
|
return new ManagedSerializedForm(OneDev.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isServerRunning(File installDir) {
|
public static boolean isServerRunning(File installDir) {
|
||||||
var serverConfig = new ServerConfig(installDir);
|
var serverConfig = new ServerConfig(installDir);
|
||||||
try (ServerSocket ignored = new ServerSocket(serverConfig.getClusterPort())) {
|
try (ServerSocket ignored = new ServerSocket(serverConfig.getClusterPort())) {
|
||||||
@ -391,7 +395,7 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getIndexDir() {
|
public static File getIndexDir() {
|
||||||
@ -399,15 +403,15 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
FileUtils.createDir(indexDir);
|
FileUtils.createDir(indexDir);
|
||||||
return indexDir;
|
return indexDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getAssetsDir() {
|
public static File getAssetsDir() {
|
||||||
return new File(Bootstrap.getSiteDir(), "assets");
|
return new File(Bootstrap.getSiteDir(), "assets");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getMaintenanceFile(File installDir) {
|
public static File getMaintenanceFile(File installDir) {
|
||||||
return new File(installDir, "maintenance");
|
return new File(installDir, "maintenance");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restart() {
|
private void restart() {
|
||||||
if (wrapperManagerClass != null) {
|
if (wrapperManagerClass != null) {
|
||||||
try {
|
try {
|
||||||
@ -429,7 +433,7 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
if (maintenanceFile.exists()) {
|
if (maintenanceFile.exists()) {
|
||||||
logger.info("Maintenance requested, trying to stop all servers...");
|
logger.info("Maintenance requested, trying to stop all servers...");
|
||||||
clusterService.submitToAllServers(() -> {
|
clusterService.submitToAllServers(() -> {
|
||||||
if (!localServer.equals(clusterService.getLocalServerAddress()))
|
if (!localServer.equals(clusterService.getLocalServerAddress()))
|
||||||
restart();
|
restart();
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@ -441,7 +445,7 @@ public class OneDev extends AbstractPlugin implements Serializable, Runnable {
|
|||||||
}
|
}
|
||||||
restart();
|
restart();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException ignored) {
|
} catch (InterruptedException ignored) {
|
||||||
|
|||||||
@ -1425,6 +1425,7 @@ public abstract class FormComponent<T> extends LabeledWebMarkupContainer impleme
|
|||||||
* Tag to modify
|
* Tag to modify
|
||||||
* @see org.apache.wicket.Component#onComponentTag(ComponentTag)
|
* @see org.apache.wicket.Component#onComponentTag(ComponentTag)
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
protected void onComponentTag(final ComponentTag tag)
|
protected void onComponentTag(final ComponentTag tag)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user