@@ -10,10 +10,7 @@ import bubble.dao.cloud.CloudServiceDAO; | |||||
import bubble.dao.device.DeviceDAO; | import bubble.dao.device.DeviceDAO; | ||||
import bubble.model.account.*; | import bubble.model.account.*; | ||||
import bubble.model.app.*; | import bubble.model.app.*; | ||||
import bubble.model.cloud.BubbleDomain; | |||||
import bubble.model.cloud.BubbleNode; | |||||
import bubble.model.cloud.CloudCredentials; | |||||
import bubble.model.cloud.CloudService; | |||||
import bubble.model.cloud.*; | |||||
import bubble.server.BubbleConfiguration; | import bubble.server.BubbleConfiguration; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.cobbzilla.util.cache.Refreshable; | import org.cobbzilla.util.cache.Refreshable; | ||||
@@ -91,10 +88,14 @@ public class AccountDAO extends AbstractCRUDDAO<Account> implements SqlViewSearc | |||||
policyDAO.create(new AccountPolicy(account.getPolicy()).setAccount(accountUuid)); | policyDAO.create(new AccountPolicy(account.getPolicy()).setAccount(accountUuid)); | ||||
} | } | ||||
// create an uninitialized device for the account | |||||
// create an uninitialized device for the account, but only if this is a regular node network | |||||
// sage networks do not allow devices, they launch and manage other regular node networks | |||||
final BubbleNode thisNode = configuration.getThisNode(); | final BubbleNode thisNode = configuration.getThisNode(); | ||||
if (thisNode != null) { | if (thisNode != null) { | ||||
deviceDAO.ensureSpareDevice(accountUuid, thisNode.getNetwork(), true); | |||||
final BubbleNetwork thisNetwork = configuration.getThisNetwork(); | |||||
if (thisNetwork != null && thisNetwork.getInstallType() == AnsibleInstallType.node) { | |||||
deviceDAO.ensureSpareDevice(accountUuid, thisNode.getNetwork(), true); | |||||
} | |||||
} | } | ||||
if (account.hasParent()) { | if (account.hasParent()) { | ||||
@@ -1,9 +1,13 @@ | |||||
package bubble.dao.device; | package bubble.dao.device; | ||||
import bubble.dao.account.AccountOwnedEntityDAO; | import bubble.dao.account.AccountOwnedEntityDAO; | ||||
import bubble.model.cloud.AnsibleInstallType; | |||||
import bubble.model.cloud.BubbleNetwork; | |||||
import bubble.model.device.Device; | import bubble.model.device.Device; | ||||
import bubble.server.BubbleConfiguration; | |||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.hibernate.criterion.Order; | import org.hibernate.criterion.Order; | ||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.stereotype.Repository; | import org.springframework.stereotype.Repository; | ||||
import java.io.File; | import java.io.File; | ||||
@@ -11,6 +15,7 @@ import java.util.List; | |||||
import static bubble.ApiConstants.HOME_DIR; | import static bubble.ApiConstants.HOME_DIR; | ||||
import static bubble.model.device.Device.*; | import static bubble.model.device.Device.*; | ||||
import static org.cobbzilla.util.daemon.ZillaRuntime.die; | |||||
import static org.cobbzilla.util.io.FileUtil.abs; | import static org.cobbzilla.util.io.FileUtil.abs; | ||||
import static org.cobbzilla.util.io.FileUtil.touch; | import static org.cobbzilla.util.io.FileUtil.touch; | ||||
@@ -19,6 +24,8 @@ public class DeviceDAO extends AccountOwnedEntityDAO<Device> { | |||||
public static final File VPN_REFRESH_USERS_FILE = new File(HOME_DIR, ".algo_refresh_users"); | public static final File VPN_REFRESH_USERS_FILE = new File(HOME_DIR, ".algo_refresh_users"); | ||||
@Autowired private BubbleConfiguration configuration; | |||||
@Override public Order getDefaultSortOrder() { return Order.asc("ctime"); } | @Override public Order getDefaultSortOrder() { return Order.asc("ctime"); } | ||||
public Device findByAccountAndName(String accountUuid, String name) { | public Device findByAccountAndName(String accountUuid, String name) { | ||||
@@ -29,6 +36,14 @@ public class DeviceDAO extends AccountOwnedEntityDAO<Device> { | |||||
return findByUniqueFields("network", networkUuid, "name", name); | return findByUniqueFields("network", networkUuid, "name", name); | ||||
} | } | ||||
@Override public Object preCreate(Device entity) { | |||||
final BubbleNetwork thisNetwork = configuration.getThisNetwork(); | |||||
if (thisNetwork == null || thisNetwork.getInstallType() != AnsibleInstallType.node) { | |||||
return die("preCreate: cannot create devices, thisNetwork="+thisNetwork); | |||||
} | |||||
return super.preCreate(entity); | |||||
} | |||||
@Override public Device create(Device device) { | @Override public Device create(Device device) { | ||||
if (!device.uninitialized()) { | if (!device.uninitialized()) { | ||||
final String account = device.getAccount(); | final String account = device.getAccount(); | ||||
@@ -10,6 +10,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; | |||||
import lombok.Getter; | import lombok.Getter; | ||||
import lombok.NoArgsConstructor; | import lombok.NoArgsConstructor; | ||||
import lombok.Setter; | import lombok.Setter; | ||||
import lombok.ToString; | |||||
import lombok.experimental.Accessors; | import lombok.experimental.Accessors; | ||||
import org.cobbzilla.util.collection.ArrayUtil; | import org.cobbzilla.util.collection.ArrayUtil; | ||||
import org.cobbzilla.wizard.model.Identifiable; | import org.cobbzilla.wizard.model.Identifiable; | ||||
@@ -45,7 +46,7 @@ import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.ENC_PAD; | |||||
@ECTypeChildren(uriPrefix=EP_NETWORKS+"/{BubbleNetwork.name}", value={ | @ECTypeChildren(uriPrefix=EP_NETWORKS+"/{BubbleNetwork.name}", value={ | ||||
@ECTypeChild(type=BubbleNode.class, backref="network") | @ECTypeChild(type=BubbleNode.class, backref="network") | ||||
}) | }) | ||||
@Entity @NoArgsConstructor @Accessors(chain=true) | |||||
@Entity @NoArgsConstructor @Accessors(chain=true) @ToString(of={"name", "domainName", "installType"}) | |||||
@ECIndexes({ | @ECIndexes({ | ||||
@ECIndex(unique=true, of={"account", "name"}), | @ECIndex(unique=true, of={"account", "name"}), | ||||
@ECIndex(unique=true, of={"name", "domainName"}) | @ECIndex(unique=true, of={"name", "domainName"}) | ||||