@Override public PortForwardingBackend getPortForwardingBackend(String providerType) { PortForwardingBackend bkd = backends.get(providerType); DebugUtils.Assert(bkd != null, String.format("cannot find PortForwardingBackend[type:%s]", providerType)); return bkd; }
public ApplianceVmSubTypeFactory getApplianceVmSubTypeFactory(String subtype) { ApplianceVmSubTypeFactory subTypeFactory = subTypeFactories.get(subtype); DebugUtils.Assert(subTypeFactory!=null, String.format("cannot find ApplianceVmSubTypeFactory for type[%s]", subtype)); return subTypeFactory; }
@Override public VipFactory getVipFactory(String networkServiceProviderType) { VipFactory f = factories.get(networkServiceProviderType); DebugUtils.Assert(f != null, String.format("cannot find the VipFactory for the network service provider type[%s]", networkServiceProviderType)); return f; }
EntityInfo getEntityInfo(Class clz) { EntityInfo info = entityInfoMap.get(clz); DebugUtils.Assert(info != null, String.format("cannot find entity info for %s", clz.getName())); return info; }
private void reSortHosts(final List<HostInventory> sub, List<HostInventory> hosts) { DebugUtils.Assert(sub.size() <= hosts.size(), "subHosts' size cannot larger than hosts' size"); hosts.removeAll(sub); hosts.addAll(0, sub); }
public <T> void paginate(long total, Consumer<List<T>> consumer) { DebugUtils.Assert(max != null, "call limit() before paginate"); if (first == null) { first = 0; } int times = (int) (total / max) + (total % max != 0 ? 1 : 0); for (int i=0; i<times; i++) { rebuildQueryInTransaction(); consumer.accept(query.getResultList()); first += max; } }
public Ssh script(String scriptName, String parameters, Map token) { DebugUtils.Assert(script==null, String.format("every Ssh object can only specify one script")); script = new ScriptRunner(scriptName, parameters, token); return this; }
public T find() { List<T> lst = listObject(); if (lst.isEmpty()) { return null; } DebugUtils.Assert(lst.size() == 1, String.format("find expects only one result, but %s got", lst.size())); return lst.get(0); } }
@Override public <T, K> void saveExtensionAsMap(Class<T> clazz, Function<K, T> func) { List<T> exts = getExtensionList(clazz); Map<Object, Object> m = new HashMap<>(); for (T ext : exts) { K key = func.call(ext); DebugUtils.Assert(key != null, "key cannot be null"); m.put(key, ext); } extensionAsMap.put(clazz, m); }
@Override public APIAuditor.Result longJobAudit(LongJob job, APIEvent rsp) { Class resourceType = job.getAuditType(); DebugUtils.Assert(resourceType != null, String.format("resourceType mustn't be null from longjob: %s", job.getClass().getSimpleName())); return new APIAuditor.Result(getResourceUuid(job), resourceType); } }
private static String getAccountUuid(String resourceUuid) { AccountManager acntMgr = Platform.getComponentLoader().getComponent(AccountManager.class); String accountUuid = acntMgr.getOwnerAccountUuidOfResource(resourceUuid); DebugUtils.Assert(accountUuid!=null, String.format("cannot find account uuid for resource[uuid:%s]", resourceUuid)); return accountUuid; }
@Transactional private void updateCapacity(long total, long avail) { PrimaryStorageCapacityVO cvo = dbf.getEntityManager().find(PrimaryStorageCapacityVO.class, self.getUuid(), LockModeType.PESSIMISTIC_WRITE); DebugUtils.Assert(cvo != null, String.format("how can there is no PrimaryStorageCapacityVO[uuid:%s]", self.getUuid())); cvo.setTotalPhysicalCapacity(total); cvo.setAvailablePhysicalCapacity(avail); dbf.getEntityManager().merge(cvo); }
public static boolean isSameCidr(String cidr1, String cidr2) { DebugUtils.Assert(isCidr(cidr1), String.format("%s is not a cidr", cidr1)); DebugUtils.Assert(isCidr(cidr2), String.format("%s is not a cidr", cidr2)); SubnetUtils su1 = new SubnetUtils(cidr1); SubnetUtils su2 = new SubnetUtils(cidr2); return su1.getInfo().getNetworkAddress().equals(su2.getInfo().getNetworkAddress()); }
@Override public void send(List<? extends NeedReplyMessage> msgs, int parallelLevel, CloudBusSteppingCallback callback) { DebugUtils.Assert(!msgs.isEmpty(), "you cannot pass an empty message list to me"); msgs.forEach(this::evaluateMessageTimeout); new While<>(msgs).step((msg, completion) -> send(msg, new CloudBusCallBack(completion) { @Override public void run(MessageReply reply) { callback.run(msg, reply); completion.done(); } }), parallelLevel).run(new NopeNoErrorCompletion()); }
@Override protected final void setup() { Collection<T> collection = collect(); DebugUtils.Assert(collection != null, "collect() cannot return null"); for (T item : collection) { batch(forEach(item)); } } }
public static boolean isSubCidr(String cidr, String subCidr) { DebugUtils.Assert(isCidr(cidr), String.format("%s is not a cidr", cidr)); DebugUtils.Assert(isCidr(subCidr), String.format("%s is not a cidr", subCidr)); SubnetUtils.SubnetInfo range = new SubnetUtils(cidr).getInfo(); SubnetUtils.SubnetInfo sub = new SubnetUtils(subCidr).getInfo(); return range.isInRange(sub.getLowAddress()) && range.isInRange(sub.getHighAddress()); }
public static boolean isCidrOverlap(String cidr1, String cidr2) { DebugUtils.Assert(isCidr(cidr1), String.format("%s is not a cidr", cidr1)); DebugUtils.Assert(isCidr(cidr2), String.format("%s is not a cidr", cidr2)); SubnetUtils su1 = new SubnetUtils(cidr1); SubnetUtils su2 = new SubnetUtils(cidr2); SubnetUtils.SubnetInfo info1 = su1.getInfo(); SubnetUtils.SubnetInfo info2 = su2.getInfo(); return isIpv4RangeOverlap(info1.getLowAddress(), info1.getHighAddress(), info2.getLowAddress(), info2.getHighAddress()); }
private String getBackupStorageUuidFromImageInventory(ImageInventory img) { SimpleQuery<ImageBackupStorageRefVO> q = dbf.createQuery(ImageBackupStorageRefVO.class); q.select(ImageBackupStorageRefVO_.backupStorageUuid); q.add(ImageBackupStorageRefVO_.imageUuid, SimpleQuery.Op.EQ, img.getUuid()); String backupStorageUuid = q.findValue(); DebugUtils.Assert(backupStorageUuid != null, String.format("cannot find backup storage for image [uuid:%s]", img.getUuid())); return backupStorageUuid; }
@Override public String visit(ASTNode node) { DebugUtils.Assert(node instanceof ASTNode.Condition, "node not instanceof ASTNode.Condition"); if (node instanceof ASTNode.Expr) { return (String) node.accept(new ExprVisitor()); } else if (node instanceof ASTNode.LogicalOperator) { return (String) node.accept(new LogicalOperatorVisitor()); } else { throw new CloudRuntimeException("should not be here"); } } }