-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b429bb
commit 747b93c
Showing
20 changed files
with
667 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/org/faastener/core/factextraction/FactExtractionProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.faastener.core.factextraction; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.faastener.core.model.common.FilterType; | ||
import org.faastener.core.model.domain.factsources.tosca.ToscaQuery; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class FactExtractionProcessor { | ||
private ToscaQuery factSource; | ||
private List<ToscaFact> extractedFacts; | ||
private Map<String, ToscaFactMapping> factMappings = Map.of( | ||
"faas.runtime", new ToscaFactMapping("faas.runtime", "funcRuntimes", FilterType.CONTAINS_ANY), | ||
"faas.blobstorage", new ToscaFactMapping("faas.blobstorage", "datastoreBlob", FilterType.CONTAINS_ANY) | ||
); | ||
|
||
public FactExtractionProcessor(ToscaQuery factSource) { | ||
this.factSource = factSource; | ||
} | ||
|
||
public void extractFacts() { | ||
ToscaFactsExtractor extractor = new ToscaFactsExtractor(); | ||
extractedFacts = extractor.extractFactsForElement(factSource.getSelectedNode(), factSource.getTopology()); | ||
} | ||
|
||
public String generateQueryString() { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
for (ToscaFact fact : extractedFacts) { | ||
if (factMappings.containsKey(fact.getFactType())) { | ||
ToscaFactMapping mapping = factMappings.get(fact.getFactType()); | ||
|
||
sb.append(mapping.getCriterionId()); | ||
if (mapping.getFilterType() == FilterType.CONTAINS_ANY) { | ||
sb.append("=in=("); | ||
if ("true".equals(fact.getFactValue())) { | ||
sb.append("*"); | ||
} else { | ||
sb.append(fact.getFactValue()); | ||
} | ||
sb.append(")"); | ||
sb.append(";"); | ||
} | ||
} | ||
} | ||
if (sb.length() > 0) { | ||
sb.deleteCharAt(sb.length() - 1); | ||
} | ||
|
||
return sb.toString(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/faastener/core/factextraction/ToscaFact.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.faastener.core.factextraction; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ToscaFact { | ||
private String elementId; | ||
private String factType; | ||
private String factValue; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/faastener/core/factextraction/ToscaFactExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.faastener.core.factextraction; | ||
|
||
import java.util.Optional; | ||
|
||
import org.faastener.core.model.domain.factsources.tosca.TopologyTemplate; | ||
|
||
@FunctionalInterface | ||
public interface ToscaFactExtractor { | ||
Optional<ToscaFact> extractForElement(String elementId, TopologyTemplate topologyTemplate); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/faastener/core/factextraction/ToscaFactMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.faastener.core.factextraction; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.faastener.core.model.common.FilterType; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ToscaFactMapping { | ||
String factId; | ||
String criterionId; | ||
FilterType filterType; | ||
} |
85 changes: 85 additions & 0 deletions
85
src/main/java/org/faastener/core/factextraction/ToscaFactsExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.faastener.core.factextraction; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import lombok.NoArgsConstructor; | ||
import org.faastener.core.model.domain.factsources.tosca.NodeTemplate; | ||
import org.faastener.core.model.domain.factsources.tosca.RelationshipTemplate; | ||
import org.faastener.core.model.domain.factsources.tosca.TopologyTemplate; | ||
|
||
@NoArgsConstructor | ||
public class ToscaFactsExtractor { | ||
private final Map<String, NodeTemplate> nodesMap = new HashMap<>(); | ||
private final Map<String, RelationshipTemplate> relationshipsMap = new HashMap<>(); | ||
private final List<ToscaFactExtractor> extractors = List.of( | ||
this::extractFunctionRuntime, | ||
this::extractObjectStorageTrigger | ||
); | ||
|
||
public List<ToscaFact> extractFactsForElement(String elementId, TopologyTemplate topologyTemplate) { | ||
preprocessTopology(topologyTemplate); | ||
List<ToscaFact> res = new ArrayList<>(); | ||
|
||
for (ToscaFactExtractor extractor : extractors) { | ||
Optional<ToscaFact> extractionResult = extractor.extractForElement(elementId, topologyTemplate); | ||
extractionResult.ifPresent(res::add); | ||
} | ||
|
||
return res; | ||
} | ||
|
||
private Optional<ToscaFact> extractFunctionRuntime(String functionNodeId, TopologyTemplate topologyTemplate) { | ||
for (NodeTemplate node : topologyTemplate.getNodeTemplates()) { | ||
if (node.getId().equals(functionNodeId)) { | ||
Map<String, String> properties = node.getProperties(); | ||
if (properties.containsKey("runtime")) { | ||
ToscaFact extracted = new ToscaFact(); | ||
extracted.setElementId(functionNodeId); | ||
extracted.setFactType("faas.runtime"); | ||
extracted.setFactValue(properties.get("runtime")); | ||
|
||
return Optional.of(extracted); | ||
} | ||
} | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
|
||
private Optional<ToscaFact> extractObjectStorageTrigger(String functionNodeId, TopologyTemplate topologyTemplate) { | ||
for (RelationshipTemplate rel : topologyTemplate.getRelationshipTemplates()) { | ||
if (rel.getType().equals("{iaas.relationships.abstract}Triggers")) { | ||
String sourceNodeId = rel.getSourceElementRef(); | ||
String targetNodeId = rel.getTargetElementRef(); | ||
|
||
if (targetNodeId.equals(functionNodeId) | ||
&& nodesMap.containsKey(sourceNodeId) | ||
&& nodesMap.get(sourceNodeId).getType().equals("{iaas.nodes.abstract}ObjectStorage") | ||
) { | ||
ToscaFact extracted = new ToscaFact(); | ||
extracted.setElementId(functionNodeId); | ||
extracted.setFactType("faas.blobstorage"); | ||
extracted.setFactValue("*"); | ||
|
||
return Optional.of(extracted); | ||
} | ||
} | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
|
||
private void preprocessTopology(TopologyTemplate topologyTemplate) { | ||
for (NodeTemplate node : topologyTemplate.getNodeTemplates()) { | ||
nodesMap.put(node.getId(), node); | ||
} | ||
|
||
for (RelationshipTemplate rel : topologyTemplate.getRelationshipTemplates()) { | ||
relationshipsMap.put(rel.getId(), rel); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/org/faastener/core/model/domain/factsources/tosca/NodeTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.faastener.core.model.domain.factsources.tosca; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class NodeTemplate { | ||
private String id; | ||
private String type; | ||
private String name; | ||
private Map<String, String> properties; | ||
private List<Capability> capabilities; | ||
private List<Requirement> requirements; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/faastener/core/model/domain/factsources/tosca/RelationshipTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.faastener.core.model.domain.factsources.tosca; | ||
|
||
import java.util.Map; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class RelationshipTemplate { | ||
private String id; | ||
private String name; | ||
private String type; | ||
private Map<String, String> properties; | ||
private String sourceElementRef; | ||
private String targetElementRef; | ||
} |
12 changes: 5 additions & 7 deletions
12
...main/factsources/tosca/TNodeTemplate.java → ...domain/factsources/tosca/Requirement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
package org.faastener.core.model.domain.factsources.tosca; | ||
|
||
import java.util.Map; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class TNodeTemplate { | ||
public String id; | ||
public String type; | ||
public String name; | ||
public Map<String, String> properties; | ||
public class Requirement { | ||
private String id; | ||
private String name; | ||
private String node; | ||
private String relationship; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/org/faastener/core/model/domain/factsources/tosca/ToscaQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.faastener.core.model.domain.factsources.tosca; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ToscaQuery { | ||
private String selectedNode; | ||
private TopologyTemplate topology; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/org/faastener/core/services/QueryGenerationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.faastener.core.services; | ||
|
||
import org.faastener.core.model.domain.factsources.tosca.ToscaQuery; | ||
|
||
public interface QueryGenerationService { | ||
String generateSearchQuery(ToscaQuery factSource); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/faastener/core/services/QueryGenerationServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.faastener.core.services; | ||
|
||
import org.faastener.core.factextraction.FactExtractionProcessor; | ||
import org.faastener.core.model.domain.factsources.tosca.ToscaQuery; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class QueryGenerationServiceImpl implements QueryGenerationService { | ||
@Override | ||
public String generateSearchQuery(ToscaQuery factSource) { | ||
FactExtractionProcessor processor = new FactExtractionProcessor(factSource); | ||
processor.extractFacts(); | ||
|
||
return processor.generateQueryString(); | ||
} | ||
} |
Oops, something went wrong.