use of org.opentosca.toscana.core.transformation.logging.LogEntry in project TOSCAna by StuPro-TOSCAna.
the class CsarControllerTest method setUp.
@Before
public void setUp() throws Exception {
List<Csar> mockedCsars = new ArrayList<>();
service = mock(CsarService.class);
when(service.getCsars()).thenReturn(mockedCsars);
when(service.getCsar(anyString())).thenReturn(Optional.empty());
for (String name : MOCK_CSAR_NAMES) {
LogEntry entry = new LogEntry(0, "TestContext", "Test Message", Level.DEBUG);
Log mockLog = logMock();
when(mockLog.getLogEntries(0)).thenReturn(Collections.singletonList(entry));
Csar csar = spy(new CsarImpl(new File(""), name, mockLog));
when(service.getCsar(name)).thenReturn(Optional.of(csar));
mockedCsars.add(csar);
}
when(service.submitCsar(anyString(), any(InputStream.class))).thenAnswer(iom -> {
// Check if the csar is already known
if (service.getCsar(iom.getArguments()[0].toString()).isPresent()) {
return null;
}
// Copy "sent" data into a byte array
InputStream in = (InputStream) iom.getArguments()[1];
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
dataRead = out.toByteArray();
// Create Csar Mock
return new CsarImpl(new File(""), iom.getArguments()[0].toString(), logMock());
});
CsarController controller = new CsarController(service);
mvc = MockMvcBuilders.standaloneSetup(controller).build();
}
use of org.opentosca.toscana.core.transformation.logging.LogEntry in project TOSCAna by StuPro-TOSCAna.
the class TransformationControllerTest method preInitNonCreationTests.
// </editor-fold>
// <editor-fold desc="Util Methods">
public List<Transformation> preInitNonCreationTests() throws PlatformNotFoundException {
// add a transformation
Optional<Csar> csar = csarService.getCsar(VALID_CSAR_NAME);
assertTrue(csar.isPresent());
String[] pnames = { VALID_PLATFORM_NAME, SECOND_VALID_PLATFORM_NAME };
List<Transformation> transformations = new ArrayList<>();
for (String pname : pnames) {
LogEntry entry = new LogEntry(0, "Test Context", "Test Message", Level.DEBUG);
Log mockLog = logMock();
when(mockLog.getLogEntries(0)).thenReturn(Collections.singletonList(entry));
Transformation transformation = new TransformationImpl(csar.get(), platformService.findPlatformById(pname).get(), mockLog, modelMock());
transformation = spy(transformation);
transformations.add(transformation);
csar.get().getTransformations().put(pname, transformation);
}
return transformations;
}
use of org.opentosca.toscana.core.transformation.logging.LogEntry in project TOSCAna by StuPro-TOSCAna.
the class CsarController method getLogs.
/**
* Returns the logs from a given start index to the current end of the logger file. If the start index is higher then
* the current end index, a empty list is returned! The start parameter is a URL encoded parameter
* (<code>?start=0</code>)
* <p>
* Accessed with http call <code>GET /csars/{csar}/transformations/{platform}/logs</code>
* <table summary="">
* <tr>
* <td>HTTP-Code</td>
* <td>Mime-Type</td>
* <td>Description (Returned if)</td>
* </tr>
* <tr>
* <td>200</td>
* <td>application/hal+json</td>
* <td>Returns a Json object containing the desired part of the logger for the transformation</td>
* </tr>
* <tr>
* <td>404</td>
* <td>application/json</td>
* <td>Returns a error message if the csar is not found or if the csar does not have a transformation for the given
* name (see returned error message for details)</td>
* </tr>
* </table>
*/
@RequestMapping(path = "/{name}/logs", method = RequestMethod.GET, produces = "application/hal+json")
@ApiOperation(value = "Get the logs of a csar", tags = { "csars" }, notes = "Returns the logs for a csar, starting at a specific position. from the given start index all " + "following log lines get returned. If the start index is larger than the current last log index the operation " + "will return a empty list.")
@ApiResponses({ @ApiResponse(code = 200, message = "The operation was executed successfully", response = LogResponse.class), @ApiResponse(code = 400, message = "The given start value is less than zero", response = RestErrorResponse.class), @ApiResponse(code = 404, message = "There is no CSAR for the given identifier", response = RestErrorResponse.class) })
public ResponseEntity<LogResponse> getLogs(@ApiParam(value = "The unique identifier for the CSAR", required = true, example = "test") @PathVariable(name = "name") String csarId, @ApiParam(value = "The index of the first log entry you want (0 returns the whole log)", required = true, example = "0") @RequestParam(name = "start", required = false, defaultValue = "0") Long start) {
if (start < 0) {
throw new IndexOutOfBoundsException("the start index has to be at least 0");
}
Csar csar = getCsarForName(csarId);
Log log = csar.getLog();
List<LogEntry> entries = log.getLogEntries(Math.toIntExact(start));
return ResponseEntity.ok().body(new LogResponse(start, entries.size() == 0 ? start : start + entries.size() - 1, entries, csarId));
}
use of org.opentosca.toscana.core.transformation.logging.LogEntry in project TOSCAna by StuPro-TOSCAna.
the class TransformationController method getTransformationLogs.
/**
* Returns the logs from a given start index to the current end of the logger file. If the start index is higher then
* the current end index, a empty list is returned! The start parameter is a URL encoded parameter
* (<code>?start=0</code>)
* <p>
* Accessed with http call <code>GET /csars/{csar}/transformations/{platform}/logs</code>
* <table summary="">
* <tr>
* <td>HTTP-Code</td>
* <td>Mime-Type</td>
* <td>Description (Returned if)</td>
* </tr>
* <tr>
* <td>200</td>
* <td>application/hal+json</td>
* <td>Returns a Json object containing the desired part of the logger for the transformation</td>
* </tr>
* <tr>
* <td>404</td>
* <td>application/json</td>
* <td>Returns a error message if the csar is not found or if the csar does not have a transformation for the given
* name (see returned error message for details)</td>
* </tr>
* </table>
*/
@RequestMapping(path = "/{platform}/logs", method = RequestMethod.GET, produces = "application/hal+json")
@ApiOperation(value = "Get the logs for a Transformation", tags = { "transformations" }, notes = "Returns the logs for a transformation, starting at a specific position. from the given start index all " + "following log lines get returned. If the start index is larger than the current last log index the operation " + "will return a empty list.")
@ApiResponses({ @ApiResponse(code = 200, message = "The operation was executed successfully", response = LogResponse.class), @ApiResponse(code = 400, message = "The given start value is less than zero", response = RestErrorResponse.class), @ApiResponse(code = 404, message = "There is no CSAR for the given identifier or the CSAR does not have " + "a Transformation for the specified platform.", response = RestErrorResponse.class) })
public ResponseEntity<LogResponse> getTransformationLogs(@ApiParam(value = "The unique identifier for the CSAR", required = true, example = "test") @PathVariable(name = "csarId") String csarId, @ApiParam(value = "The identifier for the platform", required = true, example = "kubernetes") @PathVariable(name = "platform") String platformId, @ApiParam(value = "The index of the first log entry you want (0 returns the whole log)", required = true, example = "0") @RequestParam(name = "start", required = false, defaultValue = "0") Long start) {
if (start < 0) {
throw new IndexOutOfBoundsException("the start index has to be at least 0");
}
Csar csar = findByCsarId(csarId);
Transformation transformation = findTransformationByPlatform(csar, platformId);
Log log = transformation.getLog();
List<LogEntry> entries = log.getLogEntries(Math.toIntExact(start));
return ResponseEntity.ok().body(new LogResponse(start, // TODO Maybe move this calculation into the LogResponse Class
entries.size() == 0 ? start : start + entries.size() - 1, entries, platformId, csarId));
}
Aggregations