Use the owner Id only in the workspace `RuntimeIdentity` (#8859) (#9274)

* Use the owner Id only in the workspace `RuntimeIdentity` (#8859)

Signed-off-by: David Festal <dfestal@redhat.com>
6.19.x
David Festal 2018-03-30 14:28:11 +02:00 committed by GitHub
parent 5d7bbeec86
commit c19ccdcdee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 41 additions and 76 deletions

View File

@ -26,7 +26,6 @@ var (
testRuntimeID = RuntimeID{
Workspace: "my-workspace",
Environment: "my-env",
OwnerName: "me",
OwnerId: "id",
}
testMachineName = "my-machine"

View File

@ -79,9 +79,6 @@ type RuntimeID struct {
// Environment is a name of environment e.g. "default".
Environment string `json:"envName"`
// OwnerName is the name of user who is runtime owner.
OwnerName string `json:"ownerName"`
// OwnerId is an identifier of user who is runtime owner.
OwnerId string `json:"ownerId"`
}

View File

@ -97,7 +97,7 @@ func init() {
&runtimeIDRaw,
"runtime-id",
"",
"The identifier of the runtime in format 'workspace:environment:ownerName:ownerId'",
"The identifier of the runtime in format 'workspace:environment:ownerId'",
)
flag.StringVar(
&MachineName,
@ -155,10 +155,10 @@ func Parse() {
log.Fatal("Runtime ID required(set it with -runtime-id argument)")
}
parts := strings.Split(runtimeIDRaw, ":")
if len(parts) != 4 {
log.Fatalf("Expected runtime id to be in format 'workspace:env:ownerName:ownerId'")
if len(parts) != 3 {
log.Fatalf("Expected runtime id to be in format 'workspace:env:ownerId'")
}
RuntimeID = booter.RuntimeID{Workspace: parts[0], Environment: parts[1], OwnerName: parts[2], OwnerId: parts[3]}
RuntimeID = booter.RuntimeID{Workspace: parts[0], Environment: parts[1], OwnerId: parts[2]}
// machine-name
if len(MachineName) == 0 {
@ -182,7 +182,6 @@ func Print() {
log.Print(" Runtime ID:")
log.Printf(" Workspace: %s", RuntimeID.Workspace)
log.Printf(" Environment: %s", RuntimeID.Environment)
log.Printf(" OwnerName: %s", RuntimeID.OwnerName)
log.Printf(" OwnerId: %s", RuntimeID.OwnerId)
log.Printf(" Machine name: %s", MachineName)
log.Printf(" Installer timeout: %dseconds", InstallerTimeoutSec)

View File

@ -16,7 +16,5 @@ public interface RuntimeIdentity {
String getEnvName();
String getOwnerName();
String getOwnerId();
}

View File

@ -89,7 +89,6 @@ public final class Labels {
public Serializer runtimeId(RuntimeIdentity runtimeId) {
labels.put(LABEL_WORKSPACE_ID, runtimeId.getWorkspaceId());
labels.put(LABEL_WORKSPACE_ENV, runtimeId.getEnvName());
labels.put(LABEL_WORKSPACE_OWNER, runtimeId.getOwnerName());
labels.put(LABEL_WORKSPACE_OWNER_ID, runtimeId.getOwnerId());
return this;
}
@ -161,7 +160,6 @@ public final class Labels {
return new RuntimeIdentityImpl(
labels.get(LABEL_WORKSPACE_ID),
labels.get(LABEL_WORKSPACE_ENV),
labels.get(LABEL_WORKSPACE_OWNER),
labels.get(LABEL_WORKSPACE_OWNER_ID));
}

View File

@ -86,10 +86,9 @@ public class DockerBootstrapper extends AbstractBootstrapper {
+ machineName
+ " -runtime-id "
+ String.format(
"%s:%s:%s:%s",
"%s:%s:%s",
runtimeIdentity.getWorkspaceId(),
runtimeIdentity.getEnvName(),
runtimeIdentity.getOwnerName(),
runtimeIdentity.getOwnerId())
+ " -push-endpoint "
+ installerWebsocketEndpoint

View File

@ -40,11 +40,12 @@ public class DockerEnvironmentNormalizer {
Map<String, DockerContainerConfig> containers = dockerEnvironment.getContainers();
for (Map.Entry<String, DockerContainerConfig> containerEntry : containers.entrySet()) {
DockerContainerConfig containerConfig = containerEntry.getValue();
containerConfig.setContainerName(
containerNameGenerator.generateContainerName(
identity.getWorkspaceId(),
containerConfig.getId(),
identity.getOwnerName(),
identity.getOwnerId(),
containerEntry.getKey()));
}
normalizeNames(dockerEnvironment);

View File

@ -86,8 +86,7 @@ import org.testng.annotations.Test;
*/
public class DockerInternalRuntimeTest {
private static final RuntimeIdentity IDENTITY =
new RuntimeIdentityImpl("ws1", "env1", "usr1", "id1");
private static final RuntimeIdentity IDENTITY = new RuntimeIdentityImpl("ws1", "env1", "id1");
private static final String DEV_MACHINE = "DEV_MACHINE";
private static final String DB_MACHINE = "DB_MACHINE";
private static final String SERVER_1 = "serv1";

View File

@ -43,7 +43,7 @@ public class LabelsTest {
Map<String, String> serialized =
Labels.newSerializer()
.machineName("dev-machine")
.runtimeId(new RuntimeIdentityImpl("workspace123", "my-env", "owner", "id"))
.runtimeId(new RuntimeIdentityImpl("workspace123", "my-env", "id"))
.server(
"my-server1/http",
new ServerConfigImpl("8000/tcp", "http", "/api/info", emptyMap()))
@ -59,7 +59,6 @@ public class LabelsTest {
.put("org.eclipse.che.machine.name", "dev-machine")
.put("org.eclipse.che.workspace.id", "workspace123")
.put("org.eclipse.che.workspace.env", "my-env")
.put("org.eclipse.che.workspace.owner", "owner")
.put("org.eclipse.che.workspace.owner.id", "id")
.put("org.eclipse.che.server.my-server1/http.port", "8000/tcp")
.put("org.eclipse.che.server.my-server1/http.protocol", "http")
@ -90,7 +89,6 @@ public class LabelsTest {
.put("org.eclipse.che.machine.name", "dev-machine")
.put("org.eclipse.che.workspace.id", "workspace123")
.put("org.eclipse.che.workspace.env", "my-env")
.put("org.eclipse.che.workspace.owner", "owner")
.put("org.eclipse.che.workspace.owner.id", "id")
.put("org.eclipse.che.server.my-server1/http.port", "8000/tcp")
.put("org.eclipse.che.server.my-server1/http.protocol", "http")
@ -123,7 +121,6 @@ public class LabelsTest {
RuntimeIdentity runtimeId = deserializer.runtimeId();
assertEquals(runtimeId.getWorkspaceId(), "workspace123", "workspace id");
assertEquals(runtimeId.getEnvName(), "my-env", "workspace environment name");
assertEquals(runtimeId.getOwnerName(), "owner", "workspace owner name");
assertEquals(runtimeId.getOwnerId(), "id", "workspace owner id");
Map<String, ServerConfig> servers = deserializer.servers();

View File

@ -48,8 +48,8 @@ public class DockerContainersTest {
@Test
public void findsIdentifiers() throws Exception {
RuntimeIdentity id1 = new RuntimeIdentityImpl("workspace123", "default", "test", "id");
RuntimeIdentity id2 = new RuntimeIdentityImpl("workspace234", "default", "test", "id");
RuntimeIdentity id1 = new RuntimeIdentityImpl("workspace123", "default", "id");
RuntimeIdentity id2 = new RuntimeIdentityImpl("workspace234", "default", "id");
List<ContainerListEntry> entries =
asList(mockContainer(id1, "container1"), mockContainer(id2, "container2"));
@ -81,7 +81,7 @@ public class DockerContainersTest {
@Test
public void findContainers() throws Exception {
RuntimeIdentity id = new RuntimeIdentityImpl("workspace123", "default", "test", "id");
RuntimeIdentity id = new RuntimeIdentityImpl("workspace123", "default", "id");
ContainerListEntry entry1 = mockContainer(id, "container1");
ContainerListEntry entry2 = mockContainer(id, "container2");
@ -113,7 +113,7 @@ public class DockerContainersTest {
throws Exception {
when(docker.listContainers(anyObject())).thenThrow(new IOException("oops"));
containers.find(new RuntimeIdentityImpl("workspace123", "default", "test", "id"));
containers.find(new RuntimeIdentityImpl("workspace123", "default", "id"));
}
private ContainerListEntry mockContainer(RuntimeIdentity runtimeId, String containerId)

View File

@ -36,7 +36,7 @@ import org.testng.annotations.Test;
@Listeners(MockitoTestNGListener.class)
public class WsAgentServerConfigProvisionerTest {
private static final RuntimeIdentity RUNTIME_IDENTITY =
new RuntimeIdentityImpl("wsId", "env", "owner", "id");
new RuntimeIdentityImpl("wsId", "env", "id");
private static final String MACHINE_1_NAME = "machine1";
private static final String MACHINE_2_NAME = "machine2";

View File

@ -41,7 +41,7 @@ import org.testng.annotations.Test;
public class BindMountProjectsVolumeProvisionerTest {
private static final String WORKSPACE_ID = "wsId";
private static final RuntimeIdentity RUNTIME_IDENTITY =
new RuntimeIdentityImpl(WORKSPACE_ID, "env", "owner", "id");
new RuntimeIdentityImpl(WORKSPACE_ID, "env", "id");
private static final String MACHINE_1_NAME = "machine1";
private static final String MACHINE_2_NAME = "machine2";
private static final String MACHINE_3_NAME = "machine3";

View File

@ -47,7 +47,7 @@ public class SinglePortUrlRewriterTest {
return new Object[][] {
// External IP
{
new RuntimeIdentityImpl("ws123", null, null, null),
new RuntimeIdentityImpl("ws123", null, null),
"172.12.0.2",
"127.0.0.1",
"machine1",
@ -58,7 +58,7 @@ public class SinglePortUrlRewriterTest {
},
// Internal IP, protocol, path param
{
new RuntimeIdentityImpl("ws123", null, null, null),
new RuntimeIdentityImpl("ws123", null, null),
"127.0.0.1",
null,
"machine1",
@ -69,7 +69,7 @@ public class SinglePortUrlRewriterTest {
},
// Without machine name
{
new RuntimeIdentityImpl("ws123", null, null, null),
new RuntimeIdentityImpl("ws123", null, null),
"127.0.0.1",
null,
null,
@ -80,7 +80,7 @@ public class SinglePortUrlRewriterTest {
},
// Without server
{
new RuntimeIdentityImpl("ws123", null, null, null),
new RuntimeIdentityImpl("ws123", null, null),
"127.0.0.1",
null,
"machine1",
@ -101,7 +101,6 @@ public class SinglePortUrlRewriterTest {
Provider<SinglePortHostnameBuilder> provider =
() -> new SinglePortHostnameBuilder("172.12.0.2", "127.0.0.1", null);
SinglePortUrlRewriter rewriter = new SinglePortUrlRewriter(8080, provider);
rewriter.rewriteURL(
new RuntimeIdentityImpl("ws123", null, null, null), "machine1", "server", ":");
rewriter.rewriteURL(new RuntimeIdentityImpl("ws123", null, null), "machine1", "server", ":");
}
}

View File

@ -92,10 +92,9 @@ public class KubernetesBootstrapper extends AbstractBootstrapper {
+ kubernetesMachine.getName()
+ " -runtime-id "
+ String.format(
"%s:%s:%s:%s",
"%s:%s:%s",
runtimeIdentity.getWorkspaceId(),
runtimeIdentity.getEnvName(),
runtimeIdentity.getOwnerName(),
runtimeIdentity.getOwnerId())
+ " -push-endpoint "
+ installerWebsocketEndpoint

View File

@ -126,7 +126,7 @@ public class KubernetesInternalRuntimeTest {
private static final String M2_NAME = POD_NAME + '/' + CONTAINER_NAME_2;
private static final RuntimeIdentity IDENTITY =
new RuntimeIdentityImpl(WORKSPACE_ID, "env1", "usr1", "id1");
new RuntimeIdentityImpl(WORKSPACE_ID, "env1", "id1");
@Mock private KubernetesRuntimeContext<KubernetesEnvironment> context;
@Mock private EventService eventService;

View File

@ -81,7 +81,7 @@ public class CommonPVCStrategyTest {
private static final String[] WORKSPACE_SUBPATHS = {"/projects", "/logs"};
private static final RuntimeIdentity IDENTITY =
new RuntimeIdentityImpl(WORKSPACE_ID, "env1", "usr1", "id1");
new RuntimeIdentityImpl(WORKSPACE_ID, "env1", "id1");
@Mock private Pod pod;
@Mock private Pod pod2;

View File

@ -83,7 +83,7 @@ public class UniqueWorkspacePVCStrategyTest {
private static final String VOLUME_2_NAME = "vol2";
private static final RuntimeIdentity IDENTITY =
new RuntimeIdentityImpl(WORKSPACE_ID, "env1", "usr1", "id1");
new RuntimeIdentityImpl(WORKSPACE_ID, "env1", "id1");
@Mock private KubernetesEnvironment k8sEnv;
@Mock private KubernetesClientFactory clientFactory;

View File

@ -102,7 +102,7 @@ public class OpenShiftInternalRuntimeTest {
private static final String M2_NAME = POD_NAME + '/' + CONTAINER_NAME_2;
private static final RuntimeIdentity IDENTITY =
new RuntimeIdentityImpl(WORKSPACE_ID, "env1", "usr1", "id1");
new RuntimeIdentityImpl(WORKSPACE_ID, "env1", "id1");
@Mock private OpenShiftRuntimeContext context;
@Mock private EventService eventService;

View File

@ -27,11 +27,6 @@ public interface RuntimeIdentityDto extends RuntimeIdentity {
RuntimeIdentityDto withEnvName(String envName);
@Override
String getOwnerName();
RuntimeIdentityDto withOwnerName(String ownerName);
@Override
String getOwnerId();

View File

@ -246,7 +246,6 @@ public final class DtoConverter {
return newDto(RuntimeIdentityDto.class)
.withWorkspaceId(identity.getWorkspaceId())
.withEnvName(identity.getEnvName())
.withOwnerName(identity.getOwnerName())
.withOwnerId(identity.getOwnerId());
}

View File

@ -206,8 +206,7 @@ public class WorkspaceRuntimes {
}
Subject subject = EnvironmentContext.getCurrent().getSubject();
RuntimeIdentity runtimeId =
new RuntimeIdentityImpl(workspaceId, envName, subject.getUserName(), subject.getUserId());
RuntimeIdentity runtimeId = new RuntimeIdentityImpl(workspaceId, envName, subject.getUserId());
try {
InternalEnvironment internalEnv = createInternalEnvironment(environment);
RuntimeContext runtimeContext = infrastructure.prepare(runtimeId, internalEnv);

View File

@ -55,7 +55,6 @@ public abstract class AbstractBootstrapper {
RuntimeIdentityDto runtimeId = event.getRuntimeId();
if (event.getMachineName().equals(machineName)
&& runtimeIdentity.getEnvName().equals(runtimeId.getEnvName())
&& runtimeIdentity.getOwnerName().equals(runtimeId.getOwnerName())
&& runtimeIdentity.getWorkspaceId().equals(runtimeId.getWorkspaceId())) {
finishEventFuture.complete(event);

View File

@ -17,13 +17,11 @@ public final class RuntimeIdentityImpl implements RuntimeIdentity {
private final String workspaceId;
private final String envName;
private final String ownerName;
private final String ownerId;
public RuntimeIdentityImpl(String workspaceId, String envName, String ownerName, String ownerId) {
public RuntimeIdentityImpl(String workspaceId, String envName, String ownerId) {
this.workspaceId = workspaceId;
this.envName = envName;
this.ownerName = ownerName;
this.ownerId = ownerId;
}
@ -37,11 +35,6 @@ public final class RuntimeIdentityImpl implements RuntimeIdentity {
return envName;
}
@Override
public String getOwnerName() {
return ownerName;
}
@Override
public String getOwnerId() {
return ownerId;
@ -65,8 +58,8 @@ public final class RuntimeIdentityImpl implements RuntimeIdentity {
+ workspaceId
+ " environment: "
+ envName
+ " owner: "
+ ownerName
+ " ownerId: "
+ ownerId
+ " }";
}
}

View File

@ -60,7 +60,7 @@ public abstract class InternalRuntime<T extends RuntimeContext> implements Runti
@Override
public String getOwner() {
return context.getIdentity().getOwnerName();
return context.getIdentity().getOwnerId();
}
@Override

View File

@ -24,7 +24,7 @@ public class RuntimeStartInterruptedException extends InfrastructureException {
public RuntimeStartInterruptedException(RuntimeIdentity identity) {
super(
format(
"Runtime start for identity 'workspace: %s, environment: %s, owner: %s' is interrupted",
identity.getWorkspaceId(), identity.getEnvName(), identity.getOwnerName()));
"Runtime start for identity 'workspace: %s, environment: %s, ownerId: %s' is interrupted",
identity.getWorkspaceId(), identity.getEnvName(), identity.getOwnerId()));
}
}

View File

@ -527,11 +527,7 @@ public class WorkspaceManagerTest {
private TestInternalRuntime mockRuntime(WorkspaceImpl workspace, WorkspaceStatus status)
throws Exception {
RuntimeIdentity identity =
new RuntimeIdentityImpl(
workspace.getId(),
workspace.getConfig().getDefaultEnv(),
workspace.getNamespace(),
"id");
new RuntimeIdentityImpl(workspace.getId(), workspace.getConfig().getDefaultEnv(), "id");
// doAnswer(inv -> {
// final WorkspaceImpl ws = (WorkspaceImpl)inv.getArguments()[0];
// ws.setStatus(status);

View File

@ -101,7 +101,7 @@ public class WorkspaceRuntimesTest {
@Test
public void runtimeIsRecovered() throws Exception {
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "me", "myId");
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId");
mockWorkspace(identity);
RuntimeContext context = mockContext(identity);
@ -119,7 +119,7 @@ public class WorkspaceRuntimesTest {
@Test
public void runtimeIsNotRecoveredIfNoWorkspaceFound() throws Exception {
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "me", "myId");
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId");
when(workspaceDao.get(identity.getWorkspaceId())).thenThrow(new NotFoundException("no!"));
// try recover
@ -130,7 +130,7 @@ public class WorkspaceRuntimesTest {
@Test
public void runtimeIsNotRecoveredIfNoEnvironmentFound() throws Exception {
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "me", "myId");
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId");
WorkspaceImpl workspace = mockWorkspace(identity);
when(workspace.getConfig().getEnvironments()).thenReturn(emptyMap());
@ -142,7 +142,7 @@ public class WorkspaceRuntimesTest {
@Test
public void runtimeIsNotRecoveredIfInfraPreparationFailed() throws Exception {
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "me", "myId");
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId");
mockWorkspace(identity);
InternalEnvironment internalEnvironment = mock(InternalEnvironment.class);
@ -160,7 +160,7 @@ public class WorkspaceRuntimesTest {
@Test
public void runtimeIsNotRecoveredIfAnotherRuntimeWithTheSameIdentityAlreadyExists()
throws Exception {
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "me", "myId");
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId");
mockWorkspace(identity);
RuntimeContext context = mockContext(identity);
@ -203,7 +203,6 @@ public class WorkspaceRuntimesTest {
DtoFactory.newDto(RuntimeIdentityDto.class)
.withWorkspaceId("workspace123")
.withEnvName("my-env")
.withOwnerName("me")
.withOwnerId("myId");
mockWorkspace(identity);
mockContext(identity);

View File

@ -43,7 +43,7 @@ public class WorkspaceProbesFactoryTest {
private static final ServerImpl SERVER = new ServerImpl().withUrl("https://localhost:4040/path1");
private static final RuntimeIdentity IDENTITY =
new RuntimeIdentityImpl(WORKSPACE_ID, "default", "usr1", "id1");
new RuntimeIdentityImpl(WORKSPACE_ID, "default", "id1");
@Mock private MachineTokenProvider tokenProvider;

View File

@ -630,7 +630,7 @@ public class InternalRuntimeTest {
public TestInternalRuntime(URLRewriter urlRewriter, boolean running)
throws ValidationException, InfrastructureException {
super(
new TestRuntimeContext(null, new RuntimeIdentityImpl("ws", "env", "owner", "id"), null),
new TestRuntimeContext(null, new RuntimeIdentityImpl("ws", "env", "id"), null),
urlRewriter,
emptyList(),
running);

View File

@ -42,7 +42,7 @@ import org.testng.annotations.Test;
public class EnvVarEnvironmentProvisionerTest {
private static final RuntimeIdentity RUNTIME_IDENTITY =
new RuntimeIdentityImpl("testWsId", "testEnv", "testOwner", "testOwnerId");
new RuntimeIdentityImpl("testWsId", "testEnv", "testOwnerId");
@Mock private EnvVarProvider provider1;
@Mock private EnvVarProvider provider2;