-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(#3292): Add code tab to adapter view * Show pipeline code in UI * Add header * Fix checkstyle * Fix checkstyle * Fix template visitor
- Loading branch information
1 parent
11f8225
commit ae6d4b8
Showing
45 changed files
with
1,176 additions
and
161 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
123 changes: 123 additions & 0 deletions
123
.../org/apache/streampipes/connect/management/compact/generator/CompactAdapterGenerator.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,123 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.apache.streampipes.connect.management.compact.generator; | ||
|
||
import org.apache.streampipes.connect.shared.preprocessing.convert.ToOriginalSchemaConverter; | ||
import org.apache.streampipes.manager.template.CompactConfigGenerator; | ||
import org.apache.streampipes.model.connect.adapter.AdapterDescription; | ||
import org.apache.streampipes.model.connect.adapter.compact.CompactEventProperty; | ||
import org.apache.streampipes.model.connect.adapter.compact.CreateOptions; | ||
import org.apache.streampipes.model.connect.adapter.compact.EnrichmentConfig; | ||
import org.apache.streampipes.model.connect.adapter.compact.TransformationConfig; | ||
import org.apache.streampipes.model.connect.rules.TransformationRuleDescription; | ||
import org.apache.streampipes.model.connect.rules.schema.RenameRuleDescription; | ||
import org.apache.streampipes.model.connect.rules.value.AddTimestampRuleDescription; | ||
import org.apache.streampipes.model.connect.rules.value.UnitTransformRuleDescription; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class CompactAdapterGenerator { | ||
|
||
private final AdapterDescription adapterDescription; | ||
|
||
public CompactAdapterGenerator(AdapterDescription adapterDescription) { | ||
this.adapterDescription = adapterDescription; | ||
} | ||
|
||
public List<Map<String, Object>> getConfig() { | ||
var configs = new ArrayList<Map<String, Object>>(); | ||
adapterDescription.getConfig().forEach(c -> { | ||
configs.add(new CompactConfigGenerator(c).toTemplateValue()); | ||
}); | ||
return configs; | ||
} | ||
|
||
public Map<String, CompactEventProperty> getSchema() { | ||
var map = new HashMap<String, CompactEventProperty>(); | ||
var originalProperties = new ToOriginalSchemaConverter( | ||
adapterDescription.getEventSchema().getEventProperties() | ||
).getTransformedProperties(); | ||
originalProperties | ||
.forEach(ep -> map.put(ep.getRuntimeName(), new CompactEventProperty( | ||
ep.getLabel(), | ||
ep.getDescription(), | ||
ep.getPropertyScope(), | ||
ep.getSemanticType() | ||
))); | ||
return map; | ||
} | ||
|
||
public EnrichmentConfig getEnrichmentConfig() { | ||
if (hasTimestampEnrichmentRule()) { | ||
return new EnrichmentConfig(AdapterEnrichmentRuleGenerator.TIMESTAMP_FIELD); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
public TransformationConfig getTransformationConfig() { | ||
var renameRules = new HashMap<String, String>(); | ||
var unitTransformRules = new HashMap<String, String>(); | ||
if (hasTransformationRule()) { | ||
if (hasRule(RenameRuleDescription.class)) { | ||
var rules = getRules(RenameRuleDescription.class); | ||
rules.forEach(rule -> { | ||
renameRules.put(rule.getOldRuntimeKey(), rule.getNewRuntimeKey()); | ||
}); | ||
} else if (hasRule(UnitTransformRuleDescription.class)) { | ||
var rules = getRules(UnitTransformRuleDescription.class); | ||
rules.forEach(rule -> { | ||
unitTransformRules.put(rule.getRuntimeKey(), rule.getToUnitRessourceURL()); | ||
}); | ||
} | ||
} | ||
return new TransformationConfig(renameRules, unitTransformRules); | ||
} | ||
|
||
public CreateOptions getCreateOptions() { | ||
return new CreateOptions( | ||
true, | ||
true | ||
); | ||
} | ||
|
||
private boolean hasTimestampEnrichmentRule() { | ||
return hasRule(AddTimestampRuleDescription.class); | ||
} | ||
|
||
private boolean hasTransformationRule() { | ||
return adapterDescription.getRules().stream() | ||
.anyMatch(r -> hasRule(RenameRuleDescription.class) || hasRule(UnitTransformRuleDescription.class)); | ||
} | ||
|
||
private boolean hasRule(Class<? extends TransformationRuleDescription> rule) { | ||
return adapterDescription.getRules().stream().anyMatch(r -> r.getClass().equals(rule)); | ||
} | ||
|
||
private <T extends TransformationRuleDescription> List<T> getRules(Class<T> rule) { | ||
return adapterDescription.getRules() | ||
.stream() | ||
.filter(rule::isInstance) | ||
.map(rule::cast) | ||
.toList(); | ||
} | ||
} |
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
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
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
85 changes: 85 additions & 0 deletions
85
.../org/apache/streampipes/manager/pipeline/compact/generation/CompactPipelineConverter.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 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.apache.streampipes.manager.pipeline.compact.generation; | ||
|
||
import org.apache.streampipes.manager.template.CompactConfigGenerator; | ||
import org.apache.streampipes.model.pipeline.Pipeline; | ||
import org.apache.streampipes.model.pipeline.compact.CompactPipelineElement; | ||
import org.apache.streampipes.model.staticproperty.StaticProperty; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class CompactPipelineConverter { | ||
|
||
public List<CompactPipelineElement> convert(Pipeline pipeline) { | ||
var pipelineElements = new ArrayList<CompactPipelineElement>(); | ||
|
||
pipeline.getStreams().stream() | ||
.map(stream -> createElement( | ||
PipelineElementConfigurationStep.STREAM_TYPE, | ||
stream.getDom(), | ||
stream.getElementId(), | ||
null, | ||
null)) | ||
.forEach(pipelineElements::add); | ||
|
||
pipeline.getSepas().stream() | ||
.map(processor -> createElement( | ||
PipelineElementConfigurationStep.PROCESSOR_TYPE, | ||
processor.getDom(), | ||
processor.getAppId(), | ||
processor.getConnectedTo(), | ||
getConfig(processor.getStaticProperties()))) | ||
.forEach(pipelineElements::add); | ||
|
||
pipeline.getActions().stream() | ||
.map(sink -> createElement( | ||
PipelineElementConfigurationStep.SINK_TYPE, | ||
sink.getDom(), | ||
sink.getAppId(), | ||
sink.getConnectedTo(), | ||
getConfig(sink.getStaticProperties()))) | ||
.forEach(pipelineElements::add); | ||
|
||
return pipelineElements; | ||
} | ||
|
||
private CompactPipelineElement createElement(String type, | ||
String ref, | ||
String elementId, | ||
List<String> connectedTo, | ||
List<Map<String, Object>> config) { | ||
var connections = connectedTo != null ? connectedTo.stream() | ||
.map(this::replaceId) | ||
.toList() : null; | ||
return new CompactPipelineElement(type, replaceId(ref), elementId, connections, config); | ||
} | ||
|
||
public List<Map<String, Object>> getConfig(List<StaticProperty> staticProperties) { | ||
var configs = new ArrayList<Map<String, Object>>(); | ||
staticProperties.forEach(c -> configs.add(new CompactConfigGenerator(c).toTemplateValue())); | ||
return configs; | ||
} | ||
|
||
private String replaceId(String id) { | ||
return id.replaceAll(InvocablePipelineElementGenerator.ID_PREFIX, ""); | ||
} | ||
} |
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
Oops, something went wrong.