@@ -47,7 +47,11 @@ public class LocalStorageDriver extends CloudServiceDriverBase<LocalStorageConfi | |||||
@Getter(lazy=true) private final String baseDir = initBaseDir(); | @Getter(lazy=true) private final String baseDir = initBaseDir(); | ||||
public String initBaseDir() { | public String initBaseDir() { | ||||
if (!empty(config.getBaseDir())) return config.getBaseDir(); | |||||
if (!empty(config.getBaseDir())) { | |||||
final File base = new File(config.getBaseDir()); | |||||
if (base.isAbsolute()) return base.getAbsolutePath(); | |||||
return new File(System.getProperty("user.home")+"/"+config.getBaseDir()).getAbsolutePath(); | |||||
} | |||||
final File standardBaseDir = new File(LOCAL_STORAGE_STANDARD_BASE_DIR); | final File standardBaseDir = new File(LOCAL_STORAGE_STANDARD_BASE_DIR); | ||||
if ((standardBaseDir.exists() || standardBaseDir.mkdirs()) && standardBaseDir.canRead() && standardBaseDir.canWrite()) { | if ((standardBaseDir.exists() || standardBaseDir.mkdirs()) && standardBaseDir.canRead() && standardBaseDir.canWrite()) { | ||||
@@ -163,6 +167,14 @@ public class LocalStorageDriver extends CloudServiceDriverBase<LocalStorageConfi | |||||
} catch (IOException e) { | } catch (IOException e) { | ||||
return die("delete: forceDelete("+abs(file)+") failed: "+shortError(e)); | return die("delete: forceDelete("+abs(file)+") failed: "+shortError(e)); | ||||
} | } | ||||
final File metaFile = metaFile(file); | |||||
if (metaFile.exists()) { | |||||
try { | |||||
FileUtils.forceDelete(metaFile); | |||||
} catch (IOException e) { | |||||
log.warn("delete: forceDelete of meta file (" + abs(metaFile) + ") failed: " + shortError(e)); | |||||
} | |||||
} | |||||
return true; | return true; | ||||
} | } | ||||
@@ -138,9 +138,14 @@ public class BackupService extends SimpleDaemon { | |||||
@Cleanup final TempDir temp = new TempDir(); | @Cleanup final TempDir temp = new TempDir(); | ||||
// 1 backup ansible snapshot (check sha256 first, we only need to do this once, it never changes) | |||||
log.info("backup: backing up ansible archive"); | |||||
backupFile(ansiblePath, new File(home, "ansible.tgz")); | |||||
// 1 backup ansible snapshot -- todo: check sha256 | |||||
final File ansibleTgz = new File(home, "ansible.tgz"); | |||||
if (ansibleTgz.exists()) { | |||||
log.info("backup: backing up ansible archive"); | |||||
backupFile(ansiblePath, ansibleTgz); | |||||
} else { | |||||
log.warn("backup: ansible archive not found, not backing up: "+abs(ansibleTgz)); | |||||
} | |||||
// 2 dump database to storage | // 2 dump database to storage | ||||
log.info("backup: backing up DB"); | log.info("backup: backing up DB"); | ||||
@@ -81,6 +81,7 @@ public class ActivationService { | |||||
CloudService publicDns = null; | CloudService publicDns = null; | ||||
CloudService localStorage = null; | CloudService localStorage = null; | ||||
CloudService networkStorage = null; | CloudService networkStorage = null; | ||||
CloudService email = null; | |||||
CloudService compute = null; | CloudService compute = null; | ||||
for (Map.Entry<String, CloudServiceConfig> requestedCloud : requestConfigs.entrySet()) { | for (Map.Entry<String, CloudServiceConfig> requestedCloud : requestConfigs.entrySet()) { | ||||
final String name = requestedCloud.getKey(); | final String name = requestedCloud.getKey(); | ||||
@@ -92,17 +93,27 @@ public class ActivationService { | |||||
} else if (errors.isValid()) { | } else if (errors.isValid()) { | ||||
final CloudService cloud = new CloudService(defaultCloud).configure(config, errors); | final CloudService cloud = new CloudService(defaultCloud).configure(config, errors); | ||||
toCreate.add(cloud); | toCreate.add(cloud); | ||||
if (defaultCloud.getType() == CloudServiceType.dns && defaultCloud.getName().equals(request.getDomain().getPublicDns()) && publicDns == null) publicDns = cloud; | |||||
if (defaultCloud.getType() == CloudServiceType.storage) { | |||||
if (localStorage == null && defaultCloud.isLocalStorage()) localStorage = cloud; | |||||
if (networkStorage == null && defaultCloud.isNotLocalStorage()) networkStorage = cloud; | |||||
switch (defaultCloud.getType()) { | |||||
case dns: | |||||
if (defaultCloud.getName().equals(request.getDomain().getPublicDns()) && publicDns == null) publicDns = cloud; | |||||
break; | |||||
case storage: | |||||
if (localStorage == null && defaultCloud.isLocalStorage()) localStorage = cloud; | |||||
if (networkStorage == null && defaultCloud.isNotLocalStorage()) networkStorage = cloud; | |||||
break; | |||||
case compute: | |||||
if (compute == null) compute = cloud; | |||||
break; | |||||
case email: | |||||
if (email == null) email = cloud; | |||||
break; | |||||
} | } | ||||
if (defaultCloud.getType() == CloudServiceType.compute && compute == null) compute = cloud; | |||||
} | } | ||||
} | } | ||||
if (publicDns == null) errors.addViolation("err.publicDns.noneSpecified"); | if (publicDns == null) errors.addViolation("err.publicDns.noneSpecified"); | ||||
if (networkStorage == null) errors.addViolation("err.storage.noneSpecified"); | if (networkStorage == null) errors.addViolation("err.storage.noneSpecified"); | ||||
if (compute == null && !configuration.testMode()) errors.addViolation("err.compute.noneSpecified"); | if (compute == null && !configuration.testMode()) errors.addViolation("err.compute.noneSpecified"); | ||||
if (email == null && !configuration.testMode()) errors.addViolation("err.email.noneSpecified"); | |||||
if (errors.isInvalid()) throw invalidEx(errors); | if (errors.isInvalid()) throw invalidEx(errors); | ||||
// create local storage if it was not provided | // create local storage if it was not provided | ||||
@@ -147,6 +147,7 @@ err.cloud.notFound=No cloud exists with this name | |||||
err.publicDns.noneSpecified=No DNS service was configured | err.publicDns.noneSpecified=No DNS service was configured | ||||
err.storage.noneSpecified=No Storage service was configured | err.storage.noneSpecified=No Storage service was configured | ||||
err.compute.noneSpecified=No Compute service was configured | err.compute.noneSpecified=No Compute service was configured | ||||
err.email.noneSpecified=No Email service was configured | |||||
err.cloud.localStorageIsReservedName=LocalStorage is a reserved name | err.cloud.localStorageIsReservedName=LocalStorage is a reserved name | ||||
# Storage driver errors | # Storage driver errors | ||||
@@ -1,26 +1,18 @@ | |||||
package bubble.test.dev; | package bubble.test.dev; | ||||
import bubble.resources.EntityConfigsResource; | |||||
import bubble.server.BubbleConfiguration; | |||||
import bubble.test.BubbleModelTestBase; | |||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.cobbzilla.wizard.server.RestServer; | |||||
import org.junit.Test; | import org.junit.Test; | ||||
import static java.util.concurrent.TimeUnit.DAYS; | import static java.util.concurrent.TimeUnit.DAYS; | ||||
import static org.cobbzilla.util.system.Sleep.sleep; | import static org.cobbzilla.util.system.Sleep.sleep; | ||||
@Slf4j | @Slf4j | ||||
public class BlankDevServerTest extends BubbleModelTestBase { | |||||
public class BlankDevServerTest extends NewBlankDevServerTest { | |||||
@Override protected String getManifest() { return "manifest-empty"; } | |||||
@Override protected boolean useMocks() { return false; } | |||||
@Override public void onStart(RestServer<BubbleConfiguration> server) { | |||||
getConfiguration().getBean(EntityConfigsResource.class).getAllowPublic().set(true); | |||||
super.onStart(server); | |||||
} | |||||
@Override protected String getDatabaseNameSuffix() { return "test"; } | |||||
@Override protected boolean dropPreExistingDatabase() { return false; } | |||||
@Override protected boolean allowPreExistingDatabase() { return true; } | |||||
@Override public boolean doTruncateDb() { return false; } | |||||
@Test public void runBlankServer () throws Exception { | @Test public void runBlankServer () throws Exception { | ||||
log.info("runBlankServer: Bubble API server started and model initialized. You may now begin testing."); | log.info("runBlankServer: Bubble API server started and model initialized. You may now begin testing."); | ||||
@@ -14,9 +14,7 @@ import static org.cobbzilla.util.system.Sleep.sleep; | |||||
public class DevServerTest extends ActivatedBubbleModelTestBase { | public class DevServerTest extends ActivatedBubbleModelTestBase { | ||||
@Override protected String getManifest() { return "manifest-dev"; } | @Override protected String getManifest() { return "manifest-dev"; } | ||||
@Override protected boolean useMocks() { return false; } | @Override protected boolean useMocks() { return false; } | ||||
@Override protected String getDatabaseNameSuffix() { return "dev"; } | @Override protected String getDatabaseNameSuffix() { return "dev"; } | ||||
@Override protected boolean dropPreExistingDatabase() { return false; } | @Override protected boolean dropPreExistingDatabase() { return false; } | ||||
@Override protected boolean allowPreExistingDatabase() { return true; } | @Override protected boolean allowPreExistingDatabase() { return true; } | ||||
@@ -0,0 +1,29 @@ | |||||
package bubble.test.dev; | |||||
import bubble.resources.EntityConfigsResource; | |||||
import bubble.server.BubbleConfiguration; | |||||
import bubble.test.BubbleModelTestBase; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.cobbzilla.wizard.server.RestServer; | |||||
import org.junit.Test; | |||||
import static java.util.concurrent.TimeUnit.DAYS; | |||||
import static org.cobbzilla.util.system.Sleep.sleep; | |||||
@Slf4j | |||||
public class NewBlankDevServerTest extends BubbleModelTestBase { | |||||
@Override protected String getManifest() { return "manifest-empty"; } | |||||
@Override protected boolean useMocks() { return false; } | |||||
@Override public void onStart(RestServer<BubbleConfiguration> server) { | |||||
getConfiguration().getBean(EntityConfigsResource.class).getAllowPublic().set(true); | |||||
super.onStart(server); | |||||
} | |||||
@Test public void runBlankServer () throws Exception { | |||||
log.info("runBlankServer: Bubble API server started and model initialized. You may now begin testing."); | |||||
sleep(DAYS.toMillis(30), "running dev server"); | |||||
} | |||||
} |