Skip to content

Commit

Permalink
[Bug 2213350] Delete retired docker containers, networks, volumes
Browse files Browse the repository at this point in the history
After marking docker containers, volumes and networks as retired they
will be automatically removed from Admiral in 5 hours.

Change-Id: I18f7a6a3964324db8e03fe7acf131fe7d44d6c1c
Reviewed-on: https://bellevue-ci.eng.vmware.com:8080/46573
Closures-Verified: jenkins <[email protected]>
Upgrade-Verified: jenkins <[email protected]>
PG-Verified: jenkins <[email protected]>
Bellevue-Verified: jenkins <[email protected]>
CS-Verified: jenkins <[email protected]>
Reviewed-by: Sergio Sanchez <[email protected]>
  • Loading branch information
lazarin committed Oct 16, 2018
1 parent 65dc0d1 commit 85972ed
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 1.5.0-SNAPSHOT

* After marking docker containers, volumes and networks as retired they will be automatically removed from Admiral in 5 hours.

## 1.4.0-SNAPSHOT

## 1.3.2-SNAPSHOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public class HostContainerListDataCollection extends StatefulService {
.buildUriPath(FACTORY_LINK, DEFAULT_HOST_CONTAINER_LIST_DATA_COLLECTION_ID);
protected static final long DATA_COLLECTION_LOCK_TIMEOUT_MILLISECONDS = Long.getLong(
"com.vmware.admiral.data.collection.lock.timeout.milliseconds", 60000 * 5);
private static final long RETIRED_CONTAINER_EXPIRE_PERIOD_HOURS = Long.getLong(
"com.vmware.admiral.data.collection.retired.container.expiration.hours", 5);
private static final String SYSTEM_CONTAINER_NAME = "systemContainerName";
private static final int SYSTEM_CONTAINER_SSL_RETRIES_COUNT = Integer.getInteger(
"com.vmware.admiral.system.container.ssl.retries", 3);
Expand Down Expand Up @@ -1166,6 +1168,10 @@ private void handleMissingContainer(ContainerState containerState) {
// patch container status to RETIRED
ContainerState patchContainerState = new ContainerState();
patchContainerState.powerState = PowerState.RETIRED;
if (RETIRED_CONTAINER_EXPIRE_PERIOD_HOURS >= 0) {
patchContainerState.documentExpirationTimeMicros = Utils.fromNowMicrosUtc(
TimeUnit.HOURS.toMicros(RETIRED_CONTAINER_EXPIRE_PERIOD_HOURS));
}
sendRequest(Operation
.createPatch(this, containerState.documentSelfLink)
.setBodyNoCloning(patchContainerState)
Expand All @@ -1177,8 +1183,9 @@ private void handleMissingContainer(ContainerState containerState) {
logWarning("Failed to mark container %s as missing: %s",
containerState.documentSelfLink, Utils.toString(ex));
} else {
logInfo("Marked container as missing: %s",
containerState.documentSelfLink);
logInfo("Marked container as missing: %s (expiration=%d hours)",
containerState.documentSelfLink,
RETIRED_CONTAINER_EXPIRE_PERIOD_HOURS);
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class HostNetworkListDataCollection extends StatefulService {
protected static final long DATA_COLLECTION_LOCK_TIMEOUT_MILLISECONDS = Long.getLong(
"com.vmware.admiral.compute.container.network.datacollection.lock.timeout.milliseconds",
TimeUnit.MINUTES.toMillis(5));
private static final long RETIRED_NETWORK_EXPIRE_PERIOD_HOURS = Long.getLong(
"com.vmware.admiral.data.collection.retired.network.expiration.hours", 5);

private static final int NETWORKS_INSPECT_DELAY_SECONDS = Integer.parseInt(System.getProperty(
"com.vmware.admiral.compute.container.network.inspect.delay.seconds", "2"));
Expand Down Expand Up @@ -555,6 +557,10 @@ private void handleMissingContainerNetwork(ContainerNetworkState networkState) {
// patch network status to RETIRED
ContainerNetworkState patchNetworkState = new ContainerNetworkState();
patchNetworkState.powerState = PowerState.RETIRED;
if (RETIRED_NETWORK_EXPIRE_PERIOD_HOURS >= 0) {
patchNetworkState.documentExpirationTimeMicros = Utils.fromNowMicrosUtc(
TimeUnit.HOURS.toMicros(RETIRED_NETWORK_EXPIRE_PERIOD_HOURS));
}
sendRequest(Operation
.createPatch(this, networkState.documentSelfLink)
.setBodyNoCloning(patchNetworkState)
Expand All @@ -566,8 +572,8 @@ private void handleMissingContainerNetwork(ContainerNetworkState networkState) {
logWarning("Failed to mark network %s as missing: %s",
networkState.documentSelfLink, Utils.toString(ex));
} else {
logInfo("Marked network as missing: %s",
networkState.documentSelfLink);
logInfo("Marked network as missing: %s (expiration=%d hours)",
networkState.documentSelfLink, RETIRED_NETWORK_EXPIRE_PERIOD_HOURS);
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class HostVolumeListDataCollection extends StatefulService {
"__default-list-data-collection";
public static final String DEFAULT_HOST_VOLUME_LIST_DATA_COLLECTION_LINK = UriUtils
.buildUriPath(FACTORY_LINK, DEFAULT_HOST_VOLUME_LIST_DATA_COLLECTION_ID);
private static final long RETIRED_VOLUME_EXPIRE_PERIOD_HOURS = Long.getLong(
"com.vmware.admiral.data.collection.retired.volume.expiration.hours", 5);

private static final long DATA_COLLECTION_LOCK_TIMEOUT_MILLISECONDS = Long.getLong(
"com.vmware.admiral.compute.container.volume.datacollection.lock.timeout.milliseconds",
Expand Down Expand Up @@ -542,6 +544,11 @@ private void handleMissingContainerVolume(ContainerVolumeState volumeState) {
ContainerVolumeState patchVolumeState = new ContainerVolumeState();
patchVolumeState.powerState = PowerState.RETIRED;
patchVolumeState._healthFailureCount = healthFailureCount;
if (RETIRED_VOLUME_EXPIRE_PERIOD_HOURS >= 0) {
patchVolumeState.documentExpirationTimeMicros = Utils.fromNowMicrosUtc(
TimeUnit.HOURS.toMicros(RETIRED_VOLUME_EXPIRE_PERIOD_HOURS));
}

sendRequest(Operation
.createPatch(this, volumeState.documentSelfLink)
.setBodyNoCloning(patchVolumeState)
Expand All @@ -553,7 +560,8 @@ private void handleMissingContainerVolume(ContainerVolumeState volumeState) {
logWarning("Failed to mark volume %s as missing: %s",
volumeState.documentSelfLink, Utils.toString(ex));
} else {
logInfo("Marked volume as missing: %s", volumeState.documentSelfLink);
logInfo("Marked volume as missing: %s (expiration=%d hours)",
volumeState.documentSelfLink, RETIRED_VOLUME_EXPIRE_PERIOD_HOURS);
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2017 VMware, Inc. All Rights Reserved.
* Copyright (c) 2016-2018 VMware, Inc. All Rights Reserved.
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
Expand Down Expand Up @@ -442,7 +442,8 @@ public void testDataCollection() throws Throwable {
if (missingContainer.documentVersion == 0) {
return false;
} else if (missingContainer.documentVersion == 1) {
return PowerState.RETIRED == missingContainer.powerState;
return PowerState.RETIRED == missingContainer.powerState
&& missingContainer.documentExpirationTimeMicros > 0;
} else {
AtomicBoolean found = new AtomicBoolean(false);
host.testStart(1);
Expand All @@ -455,16 +456,16 @@ public void testDataCollection() throws Throwable {
if (r.hasException()) {
host.failIteration(r.getException());
} else if (r.hasResult()) {
if (PowerState.RETIRED == r.getResult().powerState) {
if (PowerState.RETIRED == r.getResult().powerState
&& r.getResult().documentExpirationTimeMicros > 0) {
found.set(true);
}
host.completeIteration();
} else {
host.completeIteration();
}
});
host.log("Missing container document version: ",
missingContainer.documentVersion);
host.log("Missing container document version: ", missingContainer.documentVersion);
host.testWait();

return found.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2017 VMware, Inc. All Rights Reserved.
* Copyright (c) 2016-2018 VMware, Inc. All Rights Reserved.
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
Expand Down Expand Up @@ -206,6 +206,7 @@ public void testNetworkIsDeletedOnTheHost() throws Throwable {
assertEquals(containerNetworkProvisioning.name, preexistingNetworkState.name);
assertEquals(containerNetworkProvisioning.id, preexistingNetworkState.id);
assertEquals(ContainerNetworkState.PowerState.RETIRED, preexistingNetworkState.powerState);
assertTrue("expiration not set", preexistingNetworkState.documentExpirationTimeMicros > 0);

assertEquals(containerNetworkCreated.documentSelfLink, preexistingNetworkState.documentSelfLink);
assertTrue((preexistingNetworkState.customProperties == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017 VMware, Inc. All Rights Reserved.
* Copyright (c) 2017-2018 VMware, Inc. All Rights Reserved.
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
Expand Down Expand Up @@ -302,6 +302,7 @@ public void testRemoveVolumesInRetiredState() throws Throwable {
volume = getDocument(ContainerVolumeState.class, volume.documentSelfLink);
assertEquals(volume._healthFailureCount, Integer.valueOf(1));
assertEquals(PowerState.RETIRED, volume.powerState);
assertTrue("expiration not set", volume.documentExpirationTimeMicros > 0);

// 2nd data collection
startAndWaitHostVolumeListDataCollection();
Expand Down

0 comments on commit 85972ed

Please sign in to comment.