@Override public void onEntityConfigChange(ArtifactStore entity) { removeFromCache(entity, entity.getId()); } }
private Map getArtifactStore(ArtifactStore artifactStore) { final HashMap<String, Object> artifactStoreAndPlans = new HashMap<>(); artifactStoreAndPlans.put("id", artifactStore.getId()); artifactStoreAndPlans.put("configuration", artifactStore.getConfigurationAsMap(true)); return artifactStoreAndPlans; }
private Map getArtifactStore(ArtifactStore artifactStore) { final HashMap<String, Object> artifactStoreAndPlans = new HashMap<>(); artifactStoreAndPlans.put("id", artifactStore.getId()); artifactStoreAndPlans.put("configuration", artifactStore.getConfigurationAsMap(true)); return artifactStoreAndPlans; }
public Map<String, String> storeIdToPluginId() { HashMap<String, String> artifactStoreToPluginId = new HashMap<>(); for (ArtifactStore artifactStore : getPluginProfiles()) { artifactStoreToPluginId.put(artifactStore.getId(), artifactStore.getPluginId()); } return artifactStoreToPluginId; } }
public ArtifactStores getArtifactStores(Set<String> storeIds) { final ArtifactStores artifactStores = new ArtifactStores(); for (ArtifactStore artifactStore : this) { if (storeIds.contains(artifactStore.getId())) { artifactStores.add(artifactStore); } } return artifactStores; } }
private void haltIfEntityWithSameIdExists(ArtifactStore artifactStore) { if (artifactStoreService.findArtifactStore(artifactStore.getId()) == null) { return; } artifactStore.addError("id", "Artifact store ids should be unique. Artifact store with the same id exists."); throw haltBecauseEntityAlreadyExists(jsonWriter(artifactStore), "artifactStore", artifactStore.getId()); } }
public String md5ForEntity(ArtifactStore artifactStore) { String cacheKey = cacheKey(artifactStore, artifactStore.getId()); return getFromCache(cacheKey, artifactStore); }
@Override public boolean isValid(CruiseConfig preprocessedConfig) { List<PipelineConfig> allPipelineConfigs = preprocessedConfig.getAllPipelineConfigs(); List<Map<JobConfigIdentifier, List<PluggableArtifactConfig>>> usedByPipelines = new ArrayList<>(); for (PipelineConfig pipelineConfig : allPipelineConfigs) { populateReferences(usedByPipelines, pipelineConfig); } List<String> pipelineNames = new ArrayList<>(); for (Map<JobConfigIdentifier, List<PluggableArtifactConfig>> jobConfigIdentifierListMap : usedByPipelines) { for (JobConfigIdentifier jobConfigIdentifier : jobConfigIdentifierListMap.keySet()) { String toString = jobConfigIdentifier.toString(); pipelineNames.add(toString); } } if (!usedByPipelines.isEmpty()) { result.unprocessableEntity(cannotDeleteResourceBecauseOfDependentPipelines(getObjectDescriptor().toLowerCase(), profile.getId(), pipelineNames)); throw new GoConfigInvalidException(preprocessedConfig, String.format("The %s '%s' is being referenced by pipeline(s): %s.", getObjectDescriptor().toLowerCase(), profile.getId(), StringUtils.join(pipelineNames, ", "))); } return true; }
private void populateReferences(List<Map<JobConfigIdentifier, List<PluggableArtifactConfig>>> usedByPipelines, PipelineConfig pipelineConfig) { for (StageConfig stage : pipelineConfig) { JobConfigs jobs = stage.getJobs(); for (JobConfig job : jobs) { final List<PluggableArtifactConfig> artifactConfigs = job.artifactConfigs().findByStoreId(profile.getId()); if (!artifactConfigs.isEmpty()) { usedByPipelines.add(Collections.singletonMap(new JobConfigIdentifier(pipelineConfig.name(), stage.name(), job.name()), artifactConfigs)); } } } } }
private boolean isRequestFresh(CruiseConfig cruiseConfig) { ArtifactStore existingProfile = findExistingProfile(cruiseConfig); boolean freshRequest = hashingService.md5ForEntity(existingProfile).equals(md5); if (!freshRequest) { result.stale(staleResourceConfig(getObjectDescriptor(), existingProfile.getId())); } return freshRequest; } }
public void delete(Username currentUser, ArtifactStore newArtifactStore, LocalizedOperationResult result) { update(currentUser, newArtifactStore, result, new DeleteArtifactStoreConfigCommand(goConfigService, newArtifactStore, artifactExtension, currentUser, result)); if (result.isSuccessful()) { result.setMessage(LocalizedMessage.resourceDeleteSuccessful("artifactStore", newArtifactStore.getId())); } }
public static void toJSON(OutputWriter outputWriter, ArtifactStore store) { outputWriter .addLinks(linksWriter -> linksWriter .addLink("self", Routes.ArtifactStoreConfig.id(store.getId())) .addAbsoluteLink("doc", Routes.ArtifactStoreConfig.DOC) .addLink("find", Routes.ArtifactStoreConfig.find())) .add("id", store.getId()) .add("plugin_id", store.getPluginId()) .addChildList("properties", listWriter -> store.forEach(property -> listWriter.addChild(propertyWriter -> ConfigurationPropertyRepresenter.toJSON(propertyWriter, property)))); if (store.hasErrors()) { Map<String, String> fieldMapping = Collections.singletonMap("pluginId", "plugin_id"); outputWriter.addChild("errors", errorWriter -> new ErrorGetter(fieldMapping).toJSON(errorWriter, store)); } }
public String update(Request req, Response res) { ArtifactStore artifactStoreFromServer = fetchEntityFromConfig(req.params(ID_PARAM)); ArtifactStore artifactStoreFromRequest = buildEntityFromRequestBody(req); if (isRenameAttempt(artifactStoreFromServer, artifactStoreFromRequest)) { throw haltBecauseRenameOfEntityIsNotSupported("artifactStore"); } if (isPutRequestStale(req, artifactStoreFromServer)) { throw haltBecauseEtagDoesNotMatch("artifactStore", artifactStoreFromServer.getId()); } HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); artifactStoreService.update(currentUsername(), etagFor(artifactStoreFromServer), artifactStoreFromRequest, result); return handleCreateOrUpdateResponse(req, res, artifactStoreFromRequest, result); }