-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Integrieren von Testmöglichkeiten für alle gewünschten Pipeline-Operationen - Aufruf der Tests von Weboberfläche
- Loading branch information
Showing
30 changed files
with
420 additions
and
1,452 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
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
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
106 changes: 106 additions & 0 deletions
106
src/main/java/net/sberg/openkim/pipeline/operation/test/PipelineOperationTestController.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,106 @@ | ||
/* | ||
* Copyright 2023 sberg it-systeme GmbH | ||
* | ||
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved | ||
* by the European Commission - subsequent versions of the EUPL (the "Licence"); | ||
* You may not use this work except in compliance with the Licence. | ||
* You may obtain a copy of the Licence at: | ||
* | ||
* http://ec.europa.eu/idabc/eupl | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the Licence is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Licence for the specific language governing permissions and | ||
* limitations under the Licence. | ||
*/ | ||
package net.sberg.openkim.pipeline.operation.test; | ||
|
||
import net.sberg.openkim.konfiguration.Konfiguration; | ||
import net.sberg.openkim.konfiguration.KonfigurationService; | ||
import net.sberg.openkim.konnektor.Konnektor; | ||
import net.sberg.openkim.log.DefaultLogger; | ||
import net.sberg.openkim.log.DefaultLoggerContext; | ||
import net.sberg.openkim.log.LogService; | ||
import net.sberg.openkim.pipeline.PipelineService; | ||
import net.sberg.openkim.pipeline.operation.DefaultPipelineOperationContext; | ||
import net.sberg.openkim.pipeline.operation.IPipelineOperation; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartHttpServletRequest; | ||
|
||
import java.util.Map; | ||
|
||
@Controller | ||
public class PipelineOperationTestController { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(PipelineOperationTestController.class); | ||
|
||
@Autowired | ||
private LogService logService; | ||
@Autowired | ||
private PipelineService pipelineService; | ||
@Autowired | ||
private KonfigurationService konfigurationService; | ||
|
||
@RequestMapping(value = "/pipelineoperationtest/uebersicht", method = RequestMethod.GET) | ||
@ResponseStatus(value = HttpStatus.OK) | ||
public String uebersicht(Model model) throws Exception { | ||
model.addAttribute("ops", pipelineService.getTestableOperations()); | ||
return "pipelineoperationtest/pipelineoperationtestFormular"; | ||
} | ||
|
||
@RequestMapping(value = "/pipelineoperationtest/lade/{opId}", method = RequestMethod.GET) | ||
@ResponseStatus(value = HttpStatus.OK) | ||
public String ladeOpIdForm(Model model, @PathVariable String opId) throws Exception { | ||
model.addAttribute("konnektoren", konfigurationService.getKonfiguration().getKonnektoren()); | ||
model.addAttribute("opId", opId); | ||
return "pipelineoperationtest/"+opId.replaceAll("\\.","_")+"_Formular"; | ||
} | ||
|
||
@RequestMapping(value = "/pipelineoperationtest/execute", method = RequestMethod.POST, consumes = {"multipart/form-data"}) | ||
@ResponseStatus(value = HttpStatus.OK) | ||
@ResponseBody | ||
public String execute(MultipartHttpServletRequest multipartRequest) throws Exception { | ||
Map<String, String[]> multipartRequestParams = multipartRequest.getParameterMap(); | ||
Konfiguration konfiguration = konfigurationService.getKonfiguration(); | ||
Konnektor konnektor = null; | ||
if (multipartRequestParams.containsKey("konnektorId")) { | ||
konnektor = konfiguration.extractKonnektor(multipartRequestParams.get("konnektorId")[0], false); | ||
} | ||
if (konnektor == null) { | ||
if (!multipartRequestParams.containsKey("withKonnektor") || Boolean.valueOf(multipartRequestParams.get("withKonnektor")[0])) { | ||
return "Konnektor kann nicht gefunden werden"; | ||
} | ||
} | ||
DefaultLoggerContext defaultLoggerContext = new DefaultLoggerContext(); | ||
DefaultLogger logger = logService.createLogger( | ||
defaultLoggerContext | ||
.buildHtmlMode(true) | ||
.buildKonnektor(konnektor) | ||
.buildMandantId(konfiguration.getMandantId()) | ||
.buildClientSystemId(konfiguration.getClientSystemId()) | ||
.buildWorkplaceId(konfiguration.getWorkplaceId()) | ||
.buildKonfiguration(konfiguration) | ||
); | ||
IPipelineOperation pipelineOperation = pipelineService.getOperation(multipartRequestParams.get("opId")[0]); | ||
DefaultPipelineOperationContext defaultPipelineOperationContext = new DefaultPipelineOperationContext(logger); | ||
multipartRequestParams.keySet().stream().forEach(key -> { | ||
defaultPipelineOperationContext.setEnvironmentValue(pipelineOperation.getName(), key, multipartRequestParams.get(key)[0]); | ||
}); | ||
|
||
pipelineOperation.execute( | ||
defaultPipelineOperationContext, | ||
pipelineOperation.getDefaultOkConsumer(), | ||
pipelineOperation.getDefaultFailConsumer() | ||
); | ||
|
||
logService.removeLogger(logger.getId()); | ||
return logger.getLogContentAsStr(); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
src/main/java/net/sberg/openkim/pipeline/operation/test/TestOperation.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,84 @@ | ||
/* | ||
* Copyright 2023 sberg it-systeme GmbH | ||
* | ||
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved | ||
* by the European Commission - subsequent versions of the EUPL (the "Licence"); | ||
* You may not use this work except in compliance with the Licence. | ||
* You may obtain a copy of the Licence at: | ||
* | ||
* http://ec.europa.eu/idabc/eupl | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the Licence is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Licence for the specific language governing permissions and | ||
* limitations under the Licence. | ||
*/ | ||
package net.sberg.openkim.pipeline.operation.test; | ||
|
||
import net.sberg.openkim.common.metrics.DefaultMetricFactory; | ||
import net.sberg.openkim.konnektor.Konnektor; | ||
import net.sberg.openkim.log.DefaultLogger; | ||
import net.sberg.openkim.pipeline.PipelineOperation; | ||
import net.sberg.openkim.pipeline.operation.DefaultPipelineOperationContext; | ||
import net.sberg.openkim.pipeline.operation.IPipelineOperation; | ||
import org.apache.james.metrics.api.TimeMetric; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.function.BiConsumer; | ||
import java.util.function.Consumer; | ||
|
||
@PipelineOperation | ||
public class TestOperation implements IPipelineOperation { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(TestOperation.class); | ||
public static final String NAME = "Test"; | ||
|
||
public static final String ENV_NAME = "name"; | ||
|
||
@Override | ||
public boolean isTestable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getHrText() { | ||
return "Testoperation"; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
|
||
@Override | ||
public Consumer<DefaultPipelineOperationContext> getDefaultOkConsumer() { | ||
return context -> { | ||
context.getLogger().logLine("Test war erfolgreich!!!"); | ||
}; | ||
} | ||
|
||
@Override | ||
public void execute(DefaultPipelineOperationContext defaultPipelineOperationContext, Consumer<DefaultPipelineOperationContext> okConsumer, BiConsumer<DefaultPipelineOperationContext, Exception> failConsumer) { | ||
TimeMetric timeMetric = null; | ||
|
||
DefaultLogger logger = defaultPipelineOperationContext.getLogger(); | ||
Konnektor konnektor = logger.getDefaultLoggerContext().getKonnektor(); | ||
|
||
try { | ||
DefaultMetricFactory metricFactory = new DefaultMetricFactory(logger); | ||
timeMetric = metricFactory.timer(NAME); | ||
Thread.sleep(5000); | ||
defaultPipelineOperationContext.getLogger().logLine("Hallo "+defaultPipelineOperationContext.getEnvironmentValue(NAME, ENV_NAME)+" danke für die 5 Sekunden Wartezeit"); | ||
timeMetric.stopAndPublish(); | ||
okConsumer.accept(defaultPipelineOperationContext); | ||
} catch (Exception e) { | ||
log.error("error on executing the TestOperation for the konnektor: " + konnektor.getIp(), e); | ||
if (timeMetric != null) { | ||
timeMetric.stopAndPublish(); | ||
} | ||
failConsumer.accept(defaultPipelineOperationContext, e); | ||
} | ||
} | ||
} |
Oops, something went wrong.