if (value != null && value instanceof String && param.resourceType() != Object.class && !StringDSL.isZStackUuid(((String) value).trim())) { errors.add(String.format("field[%s] is not a valid uuid.", f.getName()));
@Transactional private void fixImageCacheUuid() { String sql = "select c, pri.type from ImageCacheVO c, PrimaryStorageVO pri where c.primaryStorageUuid = pri.uuid" + " and c.imageUuid is null"; TypedQuery<Tuple> q = dbf.getEntityManager().createQuery(sql, Tuple.class); List<Tuple> ts = q.getResultList(); for (Tuple t : ts) { ImageCacheVO c = t.get(0, ImageCacheVO.class); String psType = t.get(1, String.class); String imgUuid; if ("Ceph".equals(psType)) { imgUuid = c.getInstallUrl().split("@")[1]; } else if ("NFS".equals(psType) || "SharedMountPoint".equals(psType)) { imgUuid = new File(c.getInstallUrl()).getName().split("\\.")[0]; } else if ("LocalStorage".equals(psType)) { String[] pair = c.getInstallUrl().split(";"); imgUuid = new File(pair[0]).getName().split("\\.")[0]; } else { throw new CloudRuntimeException(String.format("unknown primary storage type[%s] for the ImageCacheVO[id:%s]", psType, c.getId())); } if (!StringDSL.isZStackUuid(imgUuid)) { throw new CloudRuntimeException(String.format("the image UUID[%s] parsed from the URL[%s] of the ImageCacheVO[id:%s] " + "on the primary storage[type:%s] looks no correct", imgUuid, c.getInstallUrl(), c.getId(), psType)); } c.setImageUuid(imgUuid); dbf.getEntityManager().merge(c); } }
@Override public APIMessage intercept(APIMessage msg) throws ApiMessageInterceptionException { if (msg instanceof APICreateMessage) { APICreateMessage cmsg = (APICreateMessage) msg; if (cmsg.getResourceUuid() != null) { if (!StringDSL.isZStackUuid(cmsg.getResourceUuid())) { throw new ApiMessageInterceptionException(argerr("resourceUuid[%s] is not a valid uuid. A valid uuid is a UUID(v4 recommended) with '-' stripped. " + "see http://en.wikipedia.org/wiki/Universally_unique_identifier for format of UUID, the regular expression ZStack uses" + " to validate a UUID is '[0-9a-f]{8}[0-9a-f]{4}[1-5][0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12}'", cmsg.getResourceUuid())); } } } return msg; }
@Override public void validateSystemTag(String resourceUuid, Class resourceType, String systemTag) { String uuid = PrimaryStorageSystemTags.PRIMARY_STORAGE_ALLOCATOR_UUID_TAG.getTokenByTag( systemTag, PrimaryStorageSystemTags.PRIMARY_STORAGE_ALLOCATOR_UUID_TAG_TOKEN); if (!StringDSL.isZStackUuid(uuid)) { throw new ApiMessageInterceptionException(argerr("%s is invalid. %s is not a valid zstack uuid", systemTag, uuid)); } if (!dbf.isExist(uuid, PrimaryStorageVO.class)) { throw new ApiMessageInterceptionException(argerr("no primary storage[uuid:%s] found", resourceUuid)); } } });
if (!StringDSL.isZStackUuid(vo.getUuid())) { logger.warn(String.format("found a weird management node, it's UUID not a ZStack uuid, delete it. %s", JSONObjectUtil.toJsonString(ManagementNodeInventory.valueOf(vo))));