Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion agents/go-agents/bootstrapper/booter/booter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ var (
testRuntimeID = RuntimeID{
Workspace: "my-workspace",
Environment: "my-env",
OwnerName: "me",
OwnerId: "id",
}
testMachineName = "my-machine"
Expand Down
3 changes: 0 additions & 3 deletions agents/go-agents/bootstrapper/booter/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
9 changes: 4 additions & 5 deletions agents/go-agents/bootstrapper/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ public interface RuntimeIdentity {

String getEnvName();

String getOwnerName();

String getOwnerId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public Serializer machineName(String name) {
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;
}
Expand Down Expand Up @@ -161,7 +160,6 @@ public RuntimeIdentity runtimeId() {
return new RuntimeIdentityImpl(
labels.get(LABEL_WORKSPACE_ID),
labels.get(LABEL_WORKSPACE_ENV),
labels.get(LABEL_WORKSPACE_OWNER),
labels.get(LABEL_WORKSPACE_OWNER_ID));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ protected void doBootstrapAsync(String installerWebsocketEndpoint, String output
+ machineName
+ " -runtime-id "
+ String.format(
"%s:%s:%s:%s",
"%s:%s:%s",
runtimeIdentity.getWorkspaceId(),
runtimeIdentity.getEnvName(),
runtimeIdentity.getOwnerName(),
runtimeIdentity.getOwnerId())
+ " -push-endpoint "
+ installerWebsocketEndpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ public void normalize(DockerEnvironment dockerEnvironment, RuntimeIdentity ident
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@
*/
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void serialization() {
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()))
Expand All @@ -59,7 +59,6 @@ public void serialization() {
.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")
Expand Down Expand Up @@ -90,7 +89,6 @@ public void deserialization() {
.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")
Expand Down Expand Up @@ -123,7 +121,6 @@ public void deserialization() {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -81,7 +81,7 @@ public void findsIdentifiers() throws Exception {

@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");

Expand Down Expand Up @@ -113,7 +113,7 @@ public void findContainers() throws Exception {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static Object[][] urlRewritingTestProvider() {
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",
Expand All @@ -58,7 +58,7 @@ public static Object[][] urlRewritingTestProvider() {
},
// Internal IP, protocol, path param
{
new RuntimeIdentityImpl("ws123", null, null, null),
new RuntimeIdentityImpl("ws123", null, null),
"127.0.0.1",
null,
"machine1",
Expand All @@ -69,7 +69,7 @@ public static Object[][] urlRewritingTestProvider() {
},
// Without machine name
{
new RuntimeIdentityImpl("ws123", null, null, null),
new RuntimeIdentityImpl("ws123", null, null),
"127.0.0.1",
null,
null,
Expand All @@ -80,7 +80,7 @@ public static Object[][] urlRewritingTestProvider() {
},
// Without server
{
new RuntimeIdentityImpl("ws123", null, null, null),
new RuntimeIdentityImpl("ws123", null, null),
"127.0.0.1",
null,
"machine1",
Expand All @@ -101,7 +101,6 @@ public void shouldThrowExceptionWhenRewritingFails() throws Exception {
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", ":");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ protected void doBootstrapAsync(String installerWebsocketEndpoint, String output
+ kubernetesMachine.getName()
+ " -runtime-id "
+ String.format(
"%s:%s:%s:%s",
"%s:%s:%s",
runtimeIdentity.getWorkspaceId(),
runtimeIdentity.getEnvName(),
runtimeIdentity.getOwnerName(),
runtimeIdentity.getOwnerId())
+ " -push-endpoint "
+ installerWebsocketEndpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public interface RuntimeIdentityDto extends RuntimeIdentity {

RuntimeIdentityDto withEnvName(String envName);

@Override
String getOwnerName();

RuntimeIdentityDto withOwnerName(String ownerName);

@Override
String getOwnerId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ public static RuntimeIdentityDto asDto(RuntimeIdentity identity) {
return newDto(RuntimeIdentityDto.class)
.withWorkspaceId(identity.getWorkspaceId())
.withEnvName(identity.getEnvName())
.withOwnerName(identity.getOwnerName())
.withOwnerId(identity.getOwnerId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ public CompletableFuture<Void> startAsync(
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -37,11 +35,6 @@ public String getEnvName() {
return envName;
}

@Override
public String getOwnerName() {
return ownerName;
}

@Override
public String getOwnerId() {
return ownerId;
Expand All @@ -65,8 +58,8 @@ public String toString() {
+ workspaceId
+ " environment: "
+ envName
+ " owner: "
+ ownerName
+ " ownerId: "
+ ownerId
+ " }";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String getActiveEnv() {

@Override
public String getOwner() {
return context.getIdentity().getOwnerName();
return context.getIdentity().getOwnerId();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,7 @@ private void mockRuntimeStatus(WorkspaceImpl workspace, WorkspaceStatus status)
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);
Expand Down
Loading