use of com.spotify.docker.client.exceptions.NotFoundException in project docker-client by spotify.
the class DefaultDockerClientTest method testSecretOperations.
@Test
public void testSecretOperations() throws Exception {
requireDockerApiVersionAtLeast("1.25", "secret support");
for (final Secret secret : sut.listSecrets()) {
sut.deleteSecret(secret.id());
}
assertThat(sut.listSecrets().size(), equalTo(0));
final String secretData = Base64.encodeAsString("testdata".getBytes());
final Map<String, String> labels = ImmutableMap.of("foo", "bar", "1", "a");
final SecretSpec secretSpec = SecretSpec.builder().name("asecret").data(secretData).labels(labels).build();
final SecretCreateResponse response = sut.createSecret(secretSpec);
final String secretId = response.id();
assertThat(secretId, is(notNullValue()));
final SecretSpec secretSpecConflict = SecretSpec.builder().name("asecret").data(secretData).labels(labels).build();
try {
sut.createSecret(secretSpecConflict);
fail("Should fail due to secret name conflict");
} catch (ConflictException | DockerRequestException ex) {
// Ignored; Docker should return status code 409 but doesn't in some earlier versions.
// Recent versions return 409 which translates into ConflictException.
}
final SecretSpec secretSpecInvalidData = SecretSpec.builder().name("asecret2").data("plainData").labels(labels).build();
try {
sut.createSecret(secretSpecInvalidData);
fail("Should fail due to non base64 data");
} catch (DockerException ex) {
// Ignored
}
final Secret secret = sut.inspectSecret(secretId);
final List<Secret> secrets = sut.listSecrets();
assertThat(secrets.size(), equalTo(1));
assertThat(secrets, hasItem(secret));
sut.deleteSecret(secretId);
assertThat(sut.listSecrets().size(), equalTo(0));
try {
sut.inspectSecret(secretId);
fail("Should fail because of non-existant secret ID");
} catch (NotFoundException ex) {
// Ignored
}
try {
sut.deleteSecret(secretId);
fail("Should fail because of non-existant secret ID");
} catch (DockerRequestException | NotFoundException ex) {
// Ignored; Docker should return status code 404,
// but it doesn't for some reason in versions < 17.04.
// So we catch 2 different exceptions here.
}
}
use of com.spotify.docker.client.exceptions.NotFoundException in project docker-client by spotify.
the class DefaultDockerClient method inspectConfig.
@Override
public Config inspectConfig(final String configId) throws DockerException, InterruptedException {
assertApiVersionIsAbove("1.30");
final WebTarget resource = resource().path("configs").path(configId);
try {
return request(GET, Config.class, resource, resource.request(APPLICATION_JSON_TYPE));
} catch (final DockerRequestException ex) {
switch(ex.status()) {
case 404:
throw new NotFoundException("Config " + configId + " not found.", ex);
case 503:
throw new NonSwarmNodeException("Config not part of swarm.", ex);
default:
throw ex;
}
}
}
use of com.spotify.docker.client.exceptions.NotFoundException in project docker-client by spotify.
the class DefaultDockerClient method deleteConfig.
@Override
public void deleteConfig(final String configId) throws DockerException, InterruptedException {
assertApiVersionIsAbove("1.30");
final WebTarget resource = resource().path("configs").path(configId);
try {
request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE));
} catch (final DockerRequestException ex) {
switch(ex.status()) {
case 404:
throw new NotFoundException("Config " + configId + " not found.", ex);
case 503:
throw new NonSwarmNodeException("Config not part of a swarm.", ex);
default:
throw ex;
}
}
}
use of com.spotify.docker.client.exceptions.NotFoundException in project docker-client by spotify.
the class DefaultDockerClient method updateConfig.
@Override
public void updateConfig(final String configId, final Long version, final ConfigSpec nodeSpec) throws DockerException, InterruptedException {
assertApiVersionIsAbove("1.30");
final WebTarget resource = resource().path("configs").path(configId).path("update").queryParam("version", version);
try {
request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(nodeSpec));
} catch (DockerRequestException e) {
switch(e.status()) {
case 404:
throw new NotFoundException("Config " + configId + " not found.");
case 503:
throw new NonSwarmNodeException("Config not part of a swarm.", e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.NotFoundException in project docker-client by spotify.
the class DefaultDockerClient method inspectSecret.
@Override
public Secret inspectSecret(final String secretId) throws DockerException, InterruptedException {
assertApiVersionIsAbove("1.25");
final WebTarget resource = resource().path("secrets").path(secretId);
try {
return request(GET, Secret.class, resource, resource.request(APPLICATION_JSON_TYPE));
} catch (final DockerRequestException ex) {
switch(ex.status()) {
case 404:
throw new NotFoundException("Secret " + secretId + " not found.", ex);
case 406:
throw new NonSwarmNodeException("Server not part of swarm.", ex);
default:
throw ex;
}
}
}
Aggregations