Skip to content

Adding support for VMLimit in AzureVMTemplateBuilder #652

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>4545.v56392b_7ca_7b_a_</version>
<version>4570.v1b_c718dd3b_1e</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down Expand Up @@ -151,7 +151,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.21.4</version>
<version>10.23.0</version>
</dependency>
</dependencies>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import com.microsoft.azure.vmagent.launcher.AzureInboundLauncher;
import com.microsoft.azure.vmagent.launcher.AzureSSHLauncher;
import com.microsoft.azure.vmagent.util.Constants;
import com.microsoft.azure.vmagent.availability.NoAvailabilityRequired;

public class AzureVMTemplateBuilder extends AzureVMTemplateFluent<AzureVMTemplateBuilder> {

private AzureVMTemplateFluent<?> fluent;

public AzureVMTemplateBuilder() {
this.fluent = this;
fluent.withMaxVirtualMachinesLimit("10");

Check warning on line 17 in src/main/java/com/microsoft/azure/vmagent/builders/AzureVMTemplateBuilder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 17 is not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't right it shouldn't be here

}

public AzureVMTemplateBuilder(AzureVMAgentTemplate template) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also need to call setMaxVirtualMachinesLimit in the build method further down

Expand Down Expand Up @@ -96,7 +98,7 @@
fluent.getDescription(),
fluent.getLabels(),
fluent.getLocation(),
null,
new NoAvailabilityRequired(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change here?

fluent.getVirtualMachineSize(),
fluent.getStorageAccountNameReferenceType(),
fluent.getStorageAccountType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

public class AzureVMTemplateFluent<T extends AzureVMTemplateFluent<T>> {

private String maxVirtualMachinesLimit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private String maxVirtualMachinesLimit;
private int maxVirtualMachinesLimit;


private String name;

private String description;
Expand Down Expand Up @@ -57,157 +59,167 @@
private List<AzureTagPair> cloudTags;

public AzureVMTemplateFluent() {
maxVirtualMachinesLimit = "10";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
maxVirtualMachinesLimit = "10";
maxVirtualMachinesLimit = 10;

location = "Japan West";
virtualMachineSize = "Standard_A0";
storageAccountType = "Standard_LRS";
storageAccountNameReferenceType = "new";
diskType = Constants.DISK_MANAGED;
osDiskSize = 0;
retentionStrategy = new AzureVMCloudRetensionStrategy(Constants.DEFAULT_IDLE_RETENTION_TIME);
shutdownOnIdle = false;
usageMode = Node.Mode.NORMAL;
imageTopLevelType = Constants.IMAGE_TOP_LEVEL_BASIC;
builtInImage = new BuiltInImageBuilder().build();
advancedImage = new AdvancedImageBuilder().build();
cloudTags = new ArrayList<>();
}

//CHECKSTYLE:OFF
public T withMaxVirtualMachinesLimit(String maxVirtualMachinesLimit) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public T withMaxVirtualMachinesLimit(String maxVirtualMachinesLimit) {
public T withMaxVirtualMachinesLimit(int maxVirtualMachinesLimit) {

this.maxVirtualMachinesLimit = maxVirtualMachinesLimit;
return (T) this;
}

public T withName(String name) {
this.name = name;
return (T) this;
}

public T withTags(List<AzureTagPair> tags) {
this.cloudTags = new ArrayList<>(tags);
return (T) this;
}

public T withDescription(String description) {
this.description = description;
return (T) this;
}

public T withWorkspace(String workspace) {
this.workspace = workspace;
return (T) this;
}

public T withLabels(String labels) {
this.labels = labels;
return (T) this;
}

public T withLocation(String location) {
this.location = location;
return (T) this;
}

public T withVirtualMachineSize(String virtualMachineSize) {
this.virtualMachineSize = virtualMachineSize;
return (T) this;
}

public T withStorageAccountType(String storageAccountType) {
this.storageAccountType = storageAccountType;
return (T) this;
}

public T withNewStorageAccount(String storageAccountName) {
this.storageAccountNameReferenceType = "new";
this.newStorageAccountName = storageAccountName;
return (T) this;
}

public T withExistingStorageAccount(String storageAccountName) {
this.storageAccountNameReferenceType = "existing";
this.existingStorageAccountName = storageAccountName;
return (T) this;
}

public T withDiskType(String diskType) {
this.diskType = diskType;
return (T) this;
}

public T withEphemeralOSDisk(boolean isEphemeral) {
this.ephemeralOSDisk = isEphemeral;
return (T) this;
}

public T withEncryptionAtHost(boolean isEncryptionAtHost) {
this.encryptionAtHost = isEncryptionAtHost;
return (T) this;
}

public T withOsDiskSize(int osDiskSize) {
this.osDiskSize = osDiskSize;
return (T) this;
}

public T withRetentionStrategy(AzureVMCloudBaseRetentionStrategy retentionStrategy) {
this.retentionStrategy = retentionStrategy;
return (T) this;
}

public T addNewIdleRetentionStrategy(String retentionTime) {
this.retentionStrategy = new AzureVMCloudRetensionStrategy(Integer.parseInt(retentionTime));
return (T) this;
}

public T addNewPoolRetentionStrategy(String retentionTime, String poolSize, boolean singleUseAgents) {
AzureVMCloudPoolRetentionStrategy retentionStrategy1 =
new AzureVMCloudPoolRetentionStrategy(Integer.parseInt(retentionTime),
Integer.parseInt(poolSize));
retentionStrategy1.setSingleUseAgents(singleUseAgents);
this.retentionStrategy = retentionStrategy1;
return (T) this;
}

public T withShutdownOnIdle(boolean isShutdown) {
this.shutdownOnIdle = isShutdown;
return (T) this;
}

public T withUsageMode(Node.Mode usageMode) {
this.usageMode = usageMode;
return (T) this;
}

public T withBuiltInImage(BuiltInImage builtInImage) {
this.imageTopLevelType = Constants.IMAGE_TOP_LEVEL_BASIC;
this.builtInImage = builtInImage;
return (T) this;
}

public BuiltInImageNested addNewBuiltInImage() {
return new BuiltInImageNested();
}

public BuiltInImageNested addNewBuiltInImageLike(BuiltInImage image) {
return new BuiltInImageNested(image);
}

public T withAdvancedImage(AdvancedImage advancedImage) {
this.imageTopLevelType = Constants.IMAGE_TOP_LEVEL_ADVANCED;
this.advancedImage = advancedImage;
return (T) this;
}

public AdvancedImageNested addNewAdvancedImage() {
return new AdvancedImageNested();
}

public AdvancedImageNested addNewAdvancedImageLike(AdvancedImage image) {
return new AdvancedImageNested(image);
}

public T withAdminCredential(String credentialsId) {
this.credentialsId = credentialsId;
return (T) this;
}
//CHECKSTYLE:ON

public String getMaxVirtualMachinesLimit() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public String getMaxVirtualMachinesLimit() {
public int getMaxVirtualMachinesLimit() {

return maxVirtualMachinesLimit;

Check warning on line 220 in src/main/java/com/microsoft/azure/vmagent/builders/AzureVMTemplateFluent.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 62-220 are not covered by tests
}

public String getName() {
return name;
}
Expand Down