private void validateScope(VolumeTemplate template) { if (!(Boolean.TRUE.equals(template.getPerContainer()) || Boolean.TRUE.equals(template.getExternal()) || template .getStackId() != null)) { throw new ValidationErrorException(ValidationErrorCodes.INVALID_OPTION, "Scope is not set on the volume. Should either be per container, external or per stack"); } } }
private void validateNameUniqueness(VolumeTemplate template) { if (objectManager.find(VolumeTemplate.class, VOLUME_TEMPLATE.REMOVED, null, VOLUME_TEMPLATE.STACK_ID, template.getStackId(), VOLUME_TEMPLATE.NAME, template.getName()).size() > 0) { throw new ValidationErrorException(ValidationErrorCodes.NOT_UNIQUE, "name"); } }
/** * {@inheritDoc} */ @Override public <E extends io.cattle.platform.core.model.VolumeTemplate> E into(E into) { into.from(this); return into; }
/** * {@inheritDoc} */ @Override public void from(io.cattle.platform.core.model.VolumeTemplate from) { setId(from.getId()); setName(from.getName()); setAccountId(from.getAccountId()); setKind(from.getKind()); setUuid(from.getUuid()); setDescription(from.getDescription()); setState(from.getState()); setCreated(from.getCreated()); setRemoved(from.getRemoved()); setRemoveTime(from.getRemoveTime()); setData(from.getData()); setDriver(from.getDriver()); setStackId(from.getStackId()); setExternal(from.getExternal()); setPerContainer(from.getPerContainer()); }
Map<String, Object> cattleVolumeData = new HashMap<>(); cattleVolumeData.putAll(DataUtils.getFields(volume)); cattleVolumeData.put(ServiceConstants.FIELD_VOLUME_EXTERNAL, volume.getExternal()); cattleVolumeData.put(ServiceConstants.FIELD_VOLUME_DRIVER, volume.getDriver()); cattleVolumeData.put(ServiceConstants.FIELD_VOLUME_PER_CONTAINER, volume.getPerContainer()); Map<String, Object> composeVolumeData = new HashMap<>(); for (String cattleVolume : cattleVolumeData.keySet()) { null, true); volumesData.put(volume.getName(), composeVolumeData);
if (template.getExternal()) { VOLUME.REMOVED, null, VOLUME.NAME, template.getName()); if (volume == null) { throw new ServiceInstanceAllocateException("Failed to locate volume for instance of deployment unit [" } else { final String postfix = io.cattle.platform.util.resource.UUID.randomUUID().toString(); if (template.getPerContainer()) { String name = stack.getName() + "_" + volumeNamePostfix + "_" + this.unit.getServiceIndex() + "_" + uuid + "_"; VOLUME.REMOVED, null, VOLUME.VOLUME_TEMPLATE_ID, template.getId(), VOLUME.STACK_ID, stack.getId(), VOLUME.DEPLOYMENT_UNIT_ID, unit.getId()); for (Volume vol : volumes) { VOLUME.REMOVED, null, VOLUME.VOLUME_TEMPLATE_ID, template.getId(), VOLUME.STACK_ID, stack.getId()); for (Volume testVolume : volumes) {
private Volume createVolume(Service service, VolumeTemplate template, String name) { Map<String, Object> params = new HashMap<>(); if (template.getPerContainer()) { params.put(ServiceConstants.FIELD_DEPLOYMENT_UNIT_ID, unit.getId()); } params.put("name", name); params.put("accountId", service.getAccountId()); params.put(ServiceConstants.FIELD_STACK_ID, service.getStackId()); params.put(ServiceConstants.FIELD_VOLUME_TEMPLATE_ID, template.getId()); params.put(VolumeConstants.FIELD_VOLUME_DRIVER_OPTS, DataAccessor.fieldMap(template, VolumeConstants.FIELD_VOLUME_DRIVER_OPTS)); String driver = StringUtils.isBlank(template.getDriver()) ? VolumeConstants.LOCAL_DRIVER : template.getDriver(); params.put(VolumeConstants.FIELD_VOLUME_DRIVER, driver); params.put(VolumeConstants.FIELD_DEVICE_NUM, -1); return context.resourceDao.createAndSchedule(Volume.class, params); }
@Override public Volume doWithLock() { Volume existing = null; List<? extends Volume> volumes = context.objectManager .find(Volume.class, VOLUME.ACCOUNT_ID, service.getAccountId(), VOLUME.REMOVED, null, VOLUME.VOLUME_TEMPLATE_ID, template.getId(), VOLUME.STACK_ID, stack.getId()); for (Volume vol : volumes) { if (vol.getName().startsWith(name)) { existing = vol; break; } } if (existing != null) { return existing; } return createVolume(service, template, new String(name + postfix.substring(0, 5))); } });