Преглед на файлове

disable device creation on non-node networks

tags/v0.1.8
Jonathan Cobb преди 5 години
родител
ревизия
d1ce4ee644
променени са 3 файла, в които са добавени 24 реда и са изтрити 7 реда
  1. +7
    -6
      bubble-server/src/main/java/bubble/dao/account/AccountDAO.java
  2. +15
    -0
      bubble-server/src/main/java/bubble/dao/device/DeviceDAO.java
  3. +2
    -1
      bubble-server/src/main/java/bubble/model/cloud/BubbleNetwork.java

+ 7
- 6
bubble-server/src/main/java/bubble/dao/account/AccountDAO.java Целия файл

@@ -10,10 +10,7 @@ import bubble.dao.cloud.CloudServiceDAO;
import bubble.dao.device.DeviceDAO;
import bubble.model.account.*;
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 lombok.extern.slf4j.Slf4j;
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));
}

// 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();
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()) {


+ 15
- 0
bubble-server/src/main/java/bubble/dao/device/DeviceDAO.java Целия файл

@@ -1,9 +1,13 @@
package bubble.dao.device;

import bubble.dao.account.AccountOwnedEntityDAO;
import bubble.model.cloud.AnsibleInstallType;
import bubble.model.cloud.BubbleNetwork;
import bubble.model.device.Device;
import bubble.server.BubbleConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.io.File;
@@ -11,6 +15,7 @@ import java.util.List;

import static bubble.ApiConstants.HOME_DIR;
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.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");

@Autowired private BubbleConfiguration configuration;

@Override public Order getDefaultSortOrder() { return Order.asc("ctime"); }

public Device findByAccountAndName(String accountUuid, String name) {
@@ -29,6 +36,14 @@ public class DeviceDAO extends AccountOwnedEntityDAO<Device> {
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) {
if (!device.uninitialized()) {
final String account = device.getAccount();


+ 2
- 1
bubble-server/src/main/java/bubble/model/cloud/BubbleNetwork.java Целия файл

@@ -10,6 +10,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.cobbzilla.util.collection.ArrayUtil;
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={
@ECTypeChild(type=BubbleNode.class, backref="network")
})
@Entity @NoArgsConstructor @Accessors(chain=true)
@Entity @NoArgsConstructor @Accessors(chain=true) @ToString(of={"name", "domainName", "installType"})
@ECIndexes({
@ECIndex(unique=true, of={"account", "name"}),
@ECIndex(unique=true, of={"name", "domainName"})


Зареждане…
Отказ
Запис