Skip to content

Commit

Permalink
Track 2 SDK upgrade (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed May 7, 2021
1 parent 0cee503 commit 0bbd3d0
Show file tree
Hide file tree
Showing 21 changed files with 479 additions and 923 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ nbactions-*.xml
nb-configuration.xml
nbactions.xml
deployment.out
.env
156 changes: 17 additions & 139 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -18,7 +18,7 @@
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
Expand Down Expand Up @@ -48,147 +48,54 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<azuresdk.version>1.41.0</azuresdk.version>
<azure-storage.version>6.1.0</azure-storage.version>
<jenkins.version>2.266</jenkins.version>
<jenkins.version>2.277.2</jenkins.version>
<java.level>8</java.level>
<findbugs.failOnError>true</findbugs.failOnError>
<findbugs.excludeFilterFile>findbugs-exclude.xml</findbugs.excludeFilterFile>
<maven.javadoc.skip>true</maven.javadoc.skip>
<azure-credentials.version>177.v816b81058012</azure-credentials.version>
<azure-commons.version>1.1.2</azure-commons.version>
<guava.version>24.1.1-jre</guava.version>
<azure-credentials.version>181.v00b0d97d2686</azure-credentials.version>
<azure-commons.version>1.1.3</azure-commons.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.263.x</artifactId>
<version>26</version>
<version>807.v6d348e44c987</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-annotations</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.2</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>${azure-storage.version}</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>${azuresdk.version}</version>
<exclusions>
<exclusion>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
</exclusion>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.7.12</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
<groupId>io.jenkins.plugins</groupId>
<artifactId>azure-sdk</artifactId>
<version>7.va79ea0a60157</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>azure-credentials</artifactId>
<version>${azure-credentials.version}</version>
<exclusions>
<exclusion>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>azure-commons-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>azure-commons</artifactId>
<version>${azure-commons.version}</version>
<exclusions>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>azure-commons-core</artifactId>
<version>${azure-commons.version}</version>
<exclusions>
<exclusion>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55.2</version>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>oauth2-oidc-sdk</artifactId>
<version>7.4</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down Expand Up @@ -218,6 +125,12 @@
<artifactId>cloud-stats</artifactId>
<version>0.27</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<scope>test</scope>
<version>2.2</version>
</dependency>
</dependencies>

<repositories>
Expand Down Expand Up @@ -249,41 +162,6 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<configuration>
<minimumJavaVersion>1.8</minimumJavaVersion>
<maskClasses>
com.microsoft.jenkins.azurecommons.core.
com.google.common.
com.nimbusds.

com.microsoft.azure.AzureAsyncOperation
com.microsoft.azure.AzureClient
com.microsoft.azure.AzureEnvironment
com.microsoft.azure.AzureResponseBuilder
com.microsoft.azure.AzureServiceClient
com.microsoft.azure.AzureServiceFuture
com.microsoft.azure.CloudError
com.microsoft.azure.CloudException
com.microsoft.azure.ListOperationCallback
com.microsoft.azure.Page
com.microsoft.azure.PagedList
com.microsoft.azure.PollingState
com.microsoft.azure.Resource
com.microsoft.azure.SubResource
com.microsoft.aad.
com.microsoft.applicationinsights.
com.microsoft.azure.credentials.
com.microsoft.azure.keyvault.
com.microsoft.azure.management.
com.microsoft.azure.serializer.
com.microsoft.azure.storage.
com.microsoft.rest.
</maskClasses>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/com/microsoft/azure/vmagent/AzureVMAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package com.microsoft.azure.vmagent;

import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.microsoft.azure.management.compute.OperatingSystemTypes;
import com.microsoft.azure.util.AzureCredentials;
import com.microsoft.azure.vmagent.remote.AzureVMAgentSSHLauncher;
import com.microsoft.azure.vmagent.util.AzureUtil;
Expand Down Expand Up @@ -55,9 +55,7 @@
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -547,9 +545,6 @@ public synchronized void shutdown(Localizable reason) {
// reuse.
setEligibleForReuse(true);

final Map<String, String> properties = new HashMap<>();
properties.put("Reason", reason == null ? "Unknown reason" : reason.toString());
AzureVMAgentPlugin.sendEvent(Constants.AI_VM_AGENT, "ShutDown", properties);
}

/**
Expand Down Expand Up @@ -661,11 +656,7 @@ public synchronized void deprovision(Localizable reason) throws Exception {
parentCloud.adjustVirtualMachineCount(-1);
}

Jenkins.getInstance().removeNode(this);

final Map<String, String> properties = new HashMap<>();
properties.put("Reason", reason == null ? "Unknown reason" : reason.toString());
AzureVMAgentPlugin.sendEvent(Constants.AI_VM_AGENT, "Deprovision", properties);
Jenkins.get().removeNode(this);
}

@CheckForNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package com.microsoft.azure.vmagent;

import com.microsoft.azure.PagedList;
import com.microsoft.azure.management.Azure;
import com.microsoft.azure.management.resources.Deployment;
import com.microsoft.azure.management.resources.GenericResource;
import com.azure.core.http.rest.PagedIterable;
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.resourcemanager.resources.models.Deployment;
import com.azure.resourcemanager.resources.models.GenericResource;
import com.microsoft.azure.vmagent.exceptions.AzureCloudException;
import com.microsoft.azure.vmagent.retry.DefaultRetryStrategy;
import com.microsoft.azure.vmagent.util.AzureUtil;
Expand All @@ -38,7 +38,6 @@
import org.jenkinsci.plugins.cloudstats.CloudStatistics;
import org.jenkinsci.plugins.cloudstats.ProvisioningActivity;
import org.jenkinsci.plugins.cloudstats.TrackedItem;
import org.joda.time.DateTime;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand All @@ -49,8 +48,9 @@
import java.io.Serializable;
import java.net.URI;
import java.nio.file.Paths;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
Expand Down Expand Up @@ -231,7 +231,7 @@ public void cleanDeployments(long successTimeoutInMinutes, long failTimeoutInMin
}

try {
final Azure azureClient = cloud.getAzureClient();
final AzureResourceManager azureClient = cloud.getAzureClient();
final AzureVMManagementServiceDelegate delegate = cloud.getServiceDelegate();

// This will throw if the deployment can't be found. This could happen in a couple instances
Expand All @@ -255,19 +255,13 @@ public void cleanDeployments(long successTimeoutInMinutes, long failTimeoutInMin
continue;
}

DateTime deploymentTime = deployment.timestamp();
OffsetDateTime deploymentTime = deployment.timestamp();

LOGGER.log(getNormalLoggingLevel(),
"AzureVMAgentCleanUpTask: cleanDeployments: Deployment created on {0}",
deploymentTime.toDate());
long deploymentTimeInMillis = deploymentTime.getMillis();

// Compare to now
Calendar nowTime = Calendar.getInstance(deploymentTime.getZone().toTimeZone());
long nowTimeInMillis = nowTime.getTimeInMillis();

long diffTime = nowTimeInMillis - deploymentTimeInMillis;
long diffTimeInMinutes = diffTime / MILLIS_IN_MINUTE;
deploymentTime.toString());
long diffTimeInMinutes = ChronoUnit.MINUTES
.between(deploymentTime, OffsetDateTime.now());

String state = deployment.provisioningState();

Expand Down Expand Up @@ -363,18 +357,18 @@ public void cleanLeakedResources(
DeploymentRegistrar deploymentRegistrar) {
try {
final List<String> validVMs = getValidVMs();
final Azure azureClient = cloud.getAzureClient();
final AzureResourceManager azureClient = cloud.getAzureClient();
final AzureVMManagementServiceDelegate serviceDelegate = cloud.getServiceDelegate();
// can't use listByTag because for some reason that method strips all the tags from the outputted resources
// (https://github.com/Azure/azure-sdk-for-java/issues/1436)
final PagedList<GenericResource> resources = azureClient.genericResources()
final PagedIterable<GenericResource> resources = azureClient.genericResources()
.listByResourceGroup(resourceGroup);

if (resources == null || resources.isEmpty()) {
if (resources == null || !resources.iterator().hasNext()) {
return;
}

final PriorityQueue<GenericResource> resourcesMarkedForDeletion = new PriorityQueue<>(resources.size(),
final PriorityQueue<GenericResource> resourcesMarkedForDeletion = new PriorityQueue<>(10,
new Comparator<GenericResource>() {
@Override
public int compare(GenericResource o1, GenericResource o2) {
Expand Down

0 comments on commit 0bbd3d0

Please sign in to comment.