mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
Fix issue #601 - Make OneDev Agent docker image compatible with docker
swarm
This commit is contained in:
parent
06ab7f9f72
commit
0b2f0b0c20
4
pom.xml
4
pom.xml
@ -9,7 +9,7 @@
|
||||
<version>1.0.5</version>
|
||||
</parent>
|
||||
<artifactId>server</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
<packaging>pom</packaging>
|
||||
<build>
|
||||
<finalName>${project.groupId}.${project.artifactId}-${project.version}</finalName>
|
||||
@ -559,7 +559,7 @@
|
||||
</repositories>
|
||||
<properties>
|
||||
<commons.version>2.0.23</commons.version>
|
||||
<agent.version>1.2.8</agent.version>
|
||||
<agent.version>1.2.9</agent.version>
|
||||
<slf4j.version>1.7.30</slf4j.version>
|
||||
<logback.version>1.2.0</logback.version>
|
||||
<antlr.version>4.7.2</antlr.version>
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@ -143,10 +143,8 @@ public class DefaultAgentManager extends BaseEntityManager<Agent> implements Age
|
||||
if (token == null) {
|
||||
throw new ExplicitException("Invalid agent token");
|
||||
} else {
|
||||
Agent agent = token.getAgent();
|
||||
Agent agent = findByName(data.getName());
|
||||
if (agent == null) {
|
||||
if (findByName(data.getName()) != null)
|
||||
throw new ExplicitException("Name '" + data.getName() + "' already used by another agent");
|
||||
agent = new Agent();
|
||||
agent.setToken(token);
|
||||
agent.setOsName(data.getOsInfo().getOsName());
|
||||
@ -166,11 +164,9 @@ public class DefaultAgentManager extends BaseEntityManager<Agent> implements Age
|
||||
attributeManager.save(attribute);
|
||||
agent.getAttributes().add(attribute);
|
||||
}
|
||||
} else if (!agentSessions.containsKey(agent.getId())) {
|
||||
Agent agentWithSameName = findByName(data.getName());
|
||||
if (agentWithSameName != null && !agentWithSameName.equals(agent))
|
||||
throw new ExplicitException("Name '" + data.getName() + "' already used by another agent");
|
||||
agent.setName(data.getName());
|
||||
} else if (agentSessions.containsKey(agent.getId())) {
|
||||
throw new ExplicitException("Name '" + data.getName() + "' already used by another agent");
|
||||
} else {
|
||||
agent.setOsName(data.getOsInfo().getOsName());
|
||||
agent.setOsVersion(data.getOsInfo().getOsVersion());
|
||||
agent.setOsArch(data.getOsInfo().getOsArch());
|
||||
@ -179,8 +175,6 @@ public class DefaultAgentManager extends BaseEntityManager<Agent> implements Age
|
||||
agent.setMemory(data.getMemory());
|
||||
save(agent);
|
||||
attributeManager.syncAttributes(agent, data.getAttributes());
|
||||
} else {
|
||||
throw new ExplicitException("Token already used by another agent");
|
||||
}
|
||||
|
||||
Session prevSession = agentSessions.put(agent.getId(), session);
|
||||
@ -226,7 +220,7 @@ public class DefaultAgentManager extends BaseEntityManager<Agent> implements Age
|
||||
query.setParameter("agent", agent);
|
||||
query.executeUpdate();
|
||||
|
||||
super.delete(agent);
|
||||
dao.remove(agent);
|
||||
dao.remove(agent.getToken());
|
||||
|
||||
Session prevSession = agentSessions.remove(agent.getId());
|
||||
@ -327,8 +321,28 @@ public class DefaultAgentManager extends BaseEntityManager<Agent> implements Age
|
||||
@Transactional
|
||||
@Override
|
||||
public void delete(Collection<Agent> agents) {
|
||||
Collection<AgentToken> tokens = new HashSet<>();
|
||||
for (Agent agent: agents)
|
||||
delete(agent);
|
||||
tokens.add(agent.getToken());
|
||||
|
||||
for (AgentToken token: tokens) {
|
||||
for (Agent agent: token.getAgents()) {
|
||||
Query<?> query = getSession().createQuery("update Build set agent=null where agent=:agent");
|
||||
query.setParameter("agent", agent);
|
||||
query.executeUpdate();
|
||||
|
||||
dao.remove(agent);
|
||||
|
||||
Session prevSession = agentSessions.remove(agent.getId());
|
||||
if (prevSession != null) {
|
||||
try {
|
||||
prevSession.disconnect();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
dao.remove(token);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
||||
@ -35,14 +35,14 @@ public class DefaultAgentTokenManager extends BaseEntityManager<AgentToken> impl
|
||||
@Sessional
|
||||
@Override
|
||||
public List<AgentToken> queryUnused() {
|
||||
return getSession().createQuery("select token from AgentToken token left join token.agent agent where agent = null").list();
|
||||
return getSession().createQuery("select token from AgentToken token left join token.agents agent where agent = null").list();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Transactional
|
||||
@Override
|
||||
public void deleteUnused() {
|
||||
for (AgentToken token: (List<AgentToken>)getSession().createQuery("select token from AgentToken token left join token.agent agent where agent = null").list()) {
|
||||
for (AgentToken token: (List<AgentToken>)getSession().createQuery("select token from AgentToken token left join token.agents agent where agent = null").list()) {
|
||||
delete(token);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3722,4 +3722,7 @@ public class DataMigrator {
|
||||
}
|
||||
}
|
||||
|
||||
private void migrate79(File dataDir, Stack<Integer> versions) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,8 +5,8 @@ import static io.onedev.server.model.Agent.PROP_IP_ADDRESS;
|
||||
import static io.onedev.server.model.Agent.PROP_LAST_USED_DATE;
|
||||
import static io.onedev.server.model.Agent.PROP_MEMORY;
|
||||
import static io.onedev.server.model.Agent.PROP_NAME;
|
||||
import static io.onedev.server.model.Agent.PROP_OS_NAME;
|
||||
import static io.onedev.server.model.Agent.PROP_OS_ARCH;
|
||||
import static io.onedev.server.model.Agent.PROP_OS_NAME;
|
||||
import static io.onedev.server.model.Agent.PROP_OS_VERSION;
|
||||
import static io.onedev.server.model.Agent.PROP_PAUSED;
|
||||
|
||||
@ -24,8 +24,8 @@ import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Index;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
@ -104,8 +104,8 @@ public class Agent extends AbstractEntity {
|
||||
NAME_CPU, PROP_CPU,
|
||||
NAME_MEMORY, PROP_MEMORY);
|
||||
|
||||
@OneToOne(fetch=FetchType.LAZY)
|
||||
@JoinColumn(nullable=false, unique=true)
|
||||
@ManyToOne(fetch=FetchType.LAZY)
|
||||
@JoinColumn(nullable=false)
|
||||
private AgentToken token;
|
||||
|
||||
@OneToMany(mappedBy="agent", cascade=CascadeType.REMOVE)
|
||||
|
||||
@ -2,12 +2,12 @@ package io.onedev.server.model;
|
||||
|
||||
import static io.onedev.server.model.AgentToken.PROP_VALUE;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Index;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
@ -22,15 +22,18 @@ public class AgentToken extends AbstractEntity {
|
||||
|
||||
public static final String PROP_VALUE = "value";
|
||||
|
||||
@OneToOne(mappedBy="token", fetch=FetchType.LAZY)
|
||||
private Agent agent;
|
||||
@OneToMany(mappedBy="token")
|
||||
private Collection<Agent> agents;
|
||||
|
||||
@Column(nullable=false, unique=true)
|
||||
private String value;
|
||||
|
||||
@Nullable
|
||||
public Agent getAgent() {
|
||||
return agent;
|
||||
public Collection<Agent> getAgents() {
|
||||
return agents;
|
||||
}
|
||||
|
||||
public void setAgents(Collection<Agent> agents) {
|
||||
this.agents = agents;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package io.onedev.server.rest;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -52,12 +53,12 @@ public class AgentTokenResource {
|
||||
}
|
||||
|
||||
@Api(order=100)
|
||||
@Path("/{tokenId}/agent")
|
||||
@Path("/{tokenId}/agents")
|
||||
@GET
|
||||
public Agent getAgent(@PathParam("tokenId") Long agentTokenId) {
|
||||
public Collection<Agent> getAgent(@PathParam("tokenId") Long agentTokenId) {
|
||||
if (!SecurityUtils.isAdministrator())
|
||||
throw new UnauthorizedException();
|
||||
return tokenManager.load(agentTokenId).getAgent();
|
||||
return tokenManager.load(agentTokenId).getAgents();
|
||||
}
|
||||
|
||||
@Api(order=200)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<wicket:extend>
|
||||
<div class="mb-4">
|
||||
<div class="mb-5">
|
||||
<a wicket:id="pauseOrResume" class="btn btn-light-primary mr-2"><span wicket:id="label"></span></a>
|
||||
<a wicket:id="restart" class="btn btn-light-primary mr-2">Restart</a>
|
||||
<a wicket:id="remove" class="btn btn-light-danger mr-2">Remove</a>
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<build>
|
||||
<resources>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.authenticator.ldap.LdapModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.buildspec.gradle.GradleModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.buildspec.maven.MavenModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.buildspec.node.NodePluginModule</moduleClass>
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.executor.kubernetes.KubernetesModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.executor.serverdocker.ServerDockerModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.executor.servershell.ServerShellModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.imports.bitbucketcloud.BitbucketPluginModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.imports.gitea.GiteaPluginModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.imports.github.GitHubPluginModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.imports.gitlab.GitLabPluginModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.imports.jiracloud.JiraPluginModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.imports.youtrack.YouTrackPluginModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.report.coverage.CoverageReportModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.report.markdown.MarkdownReportModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.report.problem.ProblemReportModule</moduleClass>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<moduleClass>io.onedev.server.plugin.report.unittest.UnitTestReportModule</moduleClass>
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server-plugin</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>io.onedev</groupId>
|
||||
<artifactId>server</artifactId>
|
||||
<version>6.3.11</version>
|
||||
<version>6.3.12</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user