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