-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(entitytags): Support indexing / searching by application #2132
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.collect.Lists; | ||
import com.netflix.frigga.Names; | ||
import com.netflix.spinnaker.clouddriver.core.services.Front50Service; | ||
import com.netflix.spinnaker.clouddriver.helpers.OperationPoller; | ||
import com.netflix.spinnaker.clouddriver.model.EntityTags; | ||
|
@@ -79,6 +80,7 @@ public ElasticSearchEntityTagsProvider(ObjectMapper objectMapper, | |
|
||
@Override | ||
public Collection<EntityTags> getAll(String cloudProvider, | ||
String application, | ||
String entityType, | ||
List<String> entityIds, | ||
String idPrefix, | ||
|
@@ -94,6 +96,11 @@ public Collection<EntityTags> getAll(String cloudProvider, | |
queryBuilder = queryBuilder.must(QueryBuilders.termQuery("entityRef.cloudProvider", cloudProvider)); | ||
} | ||
|
||
if (application != null) { | ||
// restrict to a specific application (optional) | ||
queryBuilder = queryBuilder.must(QueryBuilders.termQuery("entityRef.application", application)); | ||
} | ||
|
||
if (entityIds != null && !entityIds.isEmpty()) { | ||
// restrict to a specific set of entityIds (optional) | ||
queryBuilder = queryBuilder.must(QueryBuilders.termsQuery("entityRef.entityId", entityIds)); | ||
|
@@ -461,6 +468,20 @@ private static EntityTags prepareForWrite(ObjectMapper objectMapper, EntityTags | |
|
||
copyOfEntityTags.getTags().forEach(entityTag -> entityTag.setValue(entityTag.getValueForWrite(objectMapper))); | ||
|
||
String application = copyOfEntityTags.getEntityRef().getApplication(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. crux of the change here ... this is called anytime we index something in elastic search |
||
if (application == null || application.trim().isEmpty()) { | ||
try { | ||
Names names = Names.parseName(copyOfEntityTags.getEntityRef().getEntityId()); | ||
copyOfEntityTags.getEntityRef().setApplication(names.getApp()); | ||
} catch (Exception e) { | ||
log.error( | ||
"Unable to extract application name (entityId: {})", | ||
copyOfEntityTags.getEntityRef().getEntityId(), | ||
e | ||
); | ||
} | ||
} | ||
|
||
return copyOfEntityTags; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,12 @@ public BulkUpsertEntityTagsAtomicOperationResult operate(List priorOutputs) { | |
Map<String, EntityTags> existingTags = retrieveExistingTags(tags); | ||
|
||
getTask().updateStatus(BASE_PHASE, "Merging existing tags and metadata"); | ||
tags.forEach(tag -> mergeExistingTagsAndMetadata(now, existingTags.get(tag.getId()), tag, bulkUpsertEntityTagsDescription.isPartial)); | ||
tags.forEach(tag -> mergeExistingTagsAndMetadata( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no changes here ... just took it upon myself to split an overly long line of code |
||
now, | ||
existingTags.get(tag.getId()), | ||
tag, | ||
bulkUpsertEntityTagsDescription.isPartial | ||
)); | ||
|
||
getTask().updateStatus(BASE_PHASE, "Performing batch update to durable tagging service"); | ||
Map<String, EntityTags> durableTags = front50Service.batchUpdate(new ArrayList<>(tags)) | ||
|
@@ -111,7 +116,9 @@ BASE_PHASE, format("Failed to build tag id for %s, reason: %s", tag.getId(), e.g | |
entityTags.removeAll(failed); | ||
} | ||
|
||
private void updateMetadataFromDurableTagsAndIndex(List<EntityTags> entityTags, Map<String, EntityTags> durableTags, BulkUpsertEntityTagsAtomicOperationResult result) { | ||
private void updateMetadataFromDurableTagsAndIndex(List<EntityTags> entityTags, | ||
Map<String, EntityTags> durableTags, | ||
BulkUpsertEntityTagsAtomicOperationResult result) { | ||
Collection<EntityTags> failed = new ArrayList<>(); | ||
entityTags.forEach(tag -> { | ||
try { | ||
|
@@ -153,14 +160,22 @@ public static EntityRefIdBuilder.EntityRefId entityRefId(AccountCredentialsProvi | |
|
||
if (entityRefAccount != null && entityRefAccountId == null) { | ||
// add `accountId` if not explicitly provided | ||
AccountCredentials accountCredentials = lookupAccountCredentialsByAccountIdOrName(accountCredentialsProvider, entityRefAccount, "accountName"); | ||
AccountCredentials accountCredentials = lookupAccountCredentialsByAccountIdOrName( | ||
accountCredentialsProvider, | ||
entityRefAccount, | ||
"accountName" | ||
); | ||
entityRefAccountId = accountCredentials.getAccountId(); | ||
entityRef.setAccountId(entityRefAccountId); | ||
} | ||
|
||
if (entityRefAccount == null && entityRefAccountId != null) { | ||
// add `account` if not explicitly provided | ||
AccountCredentials accountCredentials = lookupAccountCredentialsByAccountIdOrName(accountCredentialsProvider, entityRefAccountId, "accountId"); | ||
AccountCredentials accountCredentials = lookupAccountCredentialsByAccountIdOrName( | ||
accountCredentialsProvider, | ||
entityRefAccountId, | ||
"accountId" | ||
); | ||
if (accountCredentials != null) { | ||
entityRefAccount = accountCredentials.getName(); | ||
entityRef.setAccount(entityRefAccount); | ||
|
@@ -252,7 +267,9 @@ private static AccountCredentials lookupAccountCredentialsByAccountIdOrName(Acco | |
return accountCredentialsProvider.getAll().stream() | ||
.filter(c -> entityRefAccountIdOrName.equals(c.getAccountId()) || entityRefAccountIdOrName.equals(c.getName())) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException(String.format("No credentials found for %s: %s", type, entityRefAccountIdOrName))); | ||
.orElseThrow(() -> new IllegalArgumentException( | ||
String.format("No credentials found for %s: %s", type, entityRefAccountIdOrName) | ||
)); | ||
} | ||
|
||
private static Task getTask() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no change here ... just took it upon myself to split an overly long line of code