Skip to content

Commit

Permalink
Use legacy instance id instead of Instance Identity (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
sparsick authored Jan 7, 2022
1 parent 052b1a7 commit c24a7ac
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.microsoft.jenkins.containeragents.util.AzureContainerUtils;
import com.microsoft.jenkins.containeragents.util.Constants;
import com.microsoft.jenkins.containeragents.util.DockerRegistryUtils;
import com.microsoft.jenkins.containeragents.util.InstanceIdentityFacade;
import com.microsoft.jenkins.containeragents.util.CustomJenkinsFacade;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.EnvVars;
import hudson.model.ItemGroup;
Expand All @@ -45,15 +45,15 @@ public final class AciDeploymentTemplateBuilder {
= "/com/microsoft/jenkins/containeragents/aci/networkProfileSnippet.json";

private final JenkinsFacade jenkins;
private final InstanceIdentityFacade instanceIdentityFacade;
private final CustomJenkinsFacade customJenkinsFacade;

public AciDeploymentTemplateBuilder() {
this(new JenkinsFacade(), new InstanceIdentityFacade());
this(new JenkinsFacade(), new CustomJenkinsFacade());
}

AciDeploymentTemplateBuilder(JenkinsFacade jenkins, InstanceIdentityFacade instanceIdentityFacade) {
AciDeploymentTemplateBuilder(JenkinsFacade jenkins, CustomJenkinsFacade customJenkinsFacade) {
this.jenkins = jenkins;
this.instanceIdentityFacade = instanceIdentityFacade;
this.customJenkinsFacade = customJenkinsFacade;
}

@NonNull
Expand All @@ -78,7 +78,7 @@ public AciDeploymentTemplate buildDeploymentTemplate(AciCloud cloud, AciContaine
variables.put("cpu", template.getCpu());
variables.put("memory", template.getMemory());
variables.put("jenkinsInstance",
instanceIdentityFacade.getInstanceId());
customJenkinsFacade.getLegacyInstanceId());

addLogAnalytics(tmp, parameters, mapper, cloud);
addCommandNode(tmp, template.getCommand(), agent);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.microsoft.jenkins.containeragents.util;

import jenkins.model.Jenkins;

/**
* Facade to Jenkins instance . Encapsulates all calls to Jenkins instance so that tests can replace this facade
* with a stub. It is inspired by Jenkins Facade of plugin-util-api-plugin.
*
*/
public class CustomJenkinsFacade {

public String getLegacyInstanceId() {
return Jenkins.get().getLegacyInstanceId();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.microsoft.jenkins.containeragents.aci.AciCloud;
import com.microsoft.jenkins.containeragents.aci.AciContainerTemplate;
import com.microsoft.jenkins.containeragents.aci.AciPrivateIpAddress;
import com.microsoft.jenkins.containeragents.util.InstanceIdentityFacade;
import com.microsoft.jenkins.containeragents.util.CustomJenkinsFacade;
import hudson.slaves.RetentionStrategy;
import hudson.slaves.SlaveComputer;
import io.jenkins.plugins.util.JenkinsFacade;
Expand All @@ -31,10 +31,10 @@ public void setup(){
SlaveComputer slaveMock = mock(SlaveComputer.class);
when(agentMock.getComputer()).thenReturn(slaveMock);

InstanceIdentityFacade instanceIdentityFacadeMock = mock(InstanceIdentityFacade.class);
when(instanceIdentityFacadeMock.getInstanceId()).thenReturn("instanceId");
CustomJenkinsFacade customJenkinsFacadeMock = mock(CustomJenkinsFacade.class);
when(customJenkinsFacadeMock.getLegacyInstanceId()).thenReturn("instanceId");

builderUnderTest = new AciDeploymentTemplateBuilder(mock(JenkinsFacade.class), instanceIdentityFacadeMock);
builderUnderTest = new AciDeploymentTemplateBuilder(mock(JenkinsFacade.class), customJenkinsFacadeMock);
}

@Test
Expand Down

0 comments on commit c24a7ac

Please sign in to comment.