From 9616eed903552e769033ceb125727462fc35b762 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Tue, 10 Mar 2020 07:51:19 -0400 Subject: [PATCH] write roles to storage if found on classpath --- .../src/main/java/bubble/dao/cloud/AnsibleRoleDAO.java | 5 +++++ .../main/java/bubble/service/cloud/AnsiblePrepService.java | 4 ++++ .../src/main/java/bubble/service/cloud/StorageService.java | 4 ++++ .../java/bubble/service_dbfilter/DbFilterStorageService.java | 4 ++++ .../en_US/server/post_auth/ResourceMessages.properties | 1 + 5 files changed, 18 insertions(+) diff --git a/bubble-server/src/main/java/bubble/dao/cloud/AnsibleRoleDAO.java b/bubble-server/src/main/java/bubble/dao/cloud/AnsibleRoleDAO.java index 27d2c1ab..91dc25cc 100644 --- a/bubble-server/src/main/java/bubble/dao/cloud/AnsibleRoleDAO.java +++ b/bubble-server/src/main/java/bubble/dao/cloud/AnsibleRoleDAO.java @@ -108,6 +108,11 @@ public class AnsibleRoleDAO extends AccountOwnedTemplateDAO { try { @Cleanup final InputStream in = getClass().getClassLoader().getResourceAsStream(roleTgzPath); existsOnClasspath = in != null; + if (existsOnClasspath) { + if (!storageService.write(role.getAccount(), role.getTgzB64(), in)) { + log.warn("preCreate: error writing role archive from classpath:"+roleTgzPath+" -> storage:"+role.getTgzB64()); + } + } } catch (Exception ioe) { log.warn("preCreate: role archive not found in storage ("+role.getTgzB64()+") and exception searching classpath ("+roleTgzPath+"): "+shortError(ioe)); } diff --git a/bubble-server/src/main/java/bubble/service/cloud/AnsiblePrepService.java b/bubble-server/src/main/java/bubble/service/cloud/AnsiblePrepService.java index 45f6c333..052c00a5 100644 --- a/bubble-server/src/main/java/bubble/service/cloud/AnsiblePrepService.java +++ b/bubble-server/src/main/java/bubble/service/cloud/AnsiblePrepService.java @@ -123,6 +123,10 @@ public class AnsiblePrepService { for (AnsibleRole role : roles) { @Cleanup final InputStream roleStream = getTgzInputStream(node.getAccount(), role); + if (roleStream == null) { + errors.addViolation("err.role.notFound", "roleStream was null for: "+role.getTgzB64()); + continue; + } final File roleTarball = toFile(new File(tarballDir, role.getName() + ".tgz"), roleStream); final File rolesDir = new File(automation, "roles"); Tarball.unroll(roleTarball, rolesDir); diff --git a/bubble-server/src/main/java/bubble/service/cloud/StorageService.java b/bubble-server/src/main/java/bubble/service/cloud/StorageService.java index b08f43d0..cefdcc7d 100644 --- a/bubble-server/src/main/java/bubble/service/cloud/StorageService.java +++ b/bubble-server/src/main/java/bubble/service/cloud/StorageService.java @@ -5,10 +5,14 @@ package bubble.service.cloud; import java.io.IOException; +import java.io.InputStream; public interface StorageService { boolean exists(String account, String tgzB64); + boolean write(String account, String uri, InputStream data); + void delete(String account, String path) throws IOException; + } diff --git a/bubble-server/src/main/java/bubble/service_dbfilter/DbFilterStorageService.java b/bubble-server/src/main/java/bubble/service_dbfilter/DbFilterStorageService.java index c0d765a2..b19063eb 100644 --- a/bubble-server/src/main/java/bubble/service_dbfilter/DbFilterStorageService.java +++ b/bubble-server/src/main/java/bubble/service_dbfilter/DbFilterStorageService.java @@ -7,6 +7,8 @@ package bubble.service_dbfilter; import bubble.service.cloud.StorageService; import org.springframework.stereotype.Service; +import java.io.InputStream; + import static org.cobbzilla.util.daemon.ZillaRuntime.notSupported; @Service @@ -14,6 +16,8 @@ public class DbFilterStorageService implements StorageService { @Override public boolean exists(String account, String tgzB64) { return notSupported("exists"); } + @Override public boolean write(String account, String uri, InputStream data) { return notSupported("write"); } + @Override public void delete(String account, String path) { notSupported("delete"); } } diff --git a/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties b/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties index 70787515..2719c38d 100644 --- a/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties +++ b/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties @@ -696,6 +696,7 @@ err.removeRule.multipleCustomLists=More than one built-in filter list was found err.request.invalid=Request is invalid err.restoreKey.invalid=Restore key is invalid err.restoreKey.required=Restore key is required +err.role.notFound=Role not found err.role.exists=Role already exists with this name err.role.invalid=Role name mismatch err.roles.required=Roles field is required