Search in sources :

Example 1 with FossologyStatus

use of org.eclipse.sw360.datahandler.thrift.components.FossologyStatus in project sw360portal by sw360.

the class WhenComputeClearingState method the_release_is_sent_for_clearing_to.

public WhenComputeClearingState the_release_is_sent_for_clearing_to(@Quoted String clearingTeam) {
    Release release = getFirstRelease();
    Map<String, FossologyStatus> clearingTeamToFossologyStatus = release.getClearingTeamToFossologyStatus();
    clearingTeamToFossologyStatus.put(clearingTeam, FossologyStatus.SENT);
    the_clearing_state_is_computed_for(lastTestedClearingTeam);
    return self();
}
Also used : TEnumToString(org.eclipse.sw360.datahandler.TEnumToString) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 2 with FossologyStatus

use of org.eclipse.sw360.datahandler.thrift.components.FossologyStatus in project sw360portal by sw360.

the class FossologyAwarePortlet method serveFossologyStatus.

protected void serveFossologyStatus(ResourceRequest request, ResourceResponse response) throws IOException {
    DataTablesParameters parameters = DataTablesParser.parametersFrom(request);
    Release release = getReleaseForFossologyStatus(request);
    Map<String, FossologyStatus> fossologyStatus = getFossologyStatus(release);
    JSONObject jsonResponse = JSONFactoryUtil.createJSONObject();
    JSONArray data = JSONFactoryUtil.createJSONArray();
    for (Map.Entry<String, FossologyStatus> entry : fossologyStatus.entrySet()) {
        JSONObject row = JSONFactoryUtil.createJSONObject();
        row.put("0", entry.getKey());
        row.put("1", ThriftEnumUtils.enumToString(entry.getValue()));
        data.put(row);
    }
    jsonResponse.put("attachment", getFossologyUploadableAttachment(release));
    jsonResponse.put("data", data);
    jsonResponse.put("draw", parameters.getDraw());
    jsonResponse.put("recordsTotal", fossologyStatus.size());
    jsonResponse.put("recordsFiltered", fossologyStatus.size());
    writeJSON(request, response, jsonResponse);
}
Also used : DataTablesParameters(org.eclipse.sw360.portal.common.datatables.data.DataTablesParameters) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) CommonUtils.nullToEmptyMap(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyMap) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 3 with FossologyStatus

use of org.eclipse.sw360.datahandler.thrift.components.FossologyStatus in project sw360portal by sw360.

the class FossologyUploaderTest method testGetStatusInFossologyIsConnectionErrorForServerNotAvailable.

@Test
public void testGetStatusInFossologyIsConnectionErrorForServerNotAvailable() throws Exception {
    int uploadId = 43;
    String clearingTeam = "team d";
    doReturn(1).when(sshConnector).runInFossologyViaSsh(anyString(), any(OutputStream.class));
    FossologyStatus statusInFossology = fossologyUploader.getStatusInFossology(uploadId, clearingTeam);
    assertThat(statusInFossology, is(FossologyStatus.CONNECTION_FAILED));
    verify(sshConnector).runInFossologyViaSsh(anyString(), any(OutputStream.class));
}
Also used : OutputStream(java.io.OutputStream) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Test(org.junit.Test)

Example 4 with FossologyStatus

use of org.eclipse.sw360.datahandler.thrift.components.FossologyStatus in project sw360portal by sw360.

the class FossologyUploaderFunctionalTest method testRealUpload.

@Ignore
@Test
public void testRealUpload() {
    doFirstConnectionAndTrust();
    String test = "this is the content\n";
    InputStream inputStream = new ByteArrayInputStream(test.getBytes());
    final CapturerOutputStream outputStream = new CapturerOutputStream();
    final String command = String.format(FossologyUploader.FOSSOLOGY_COMMAND_UPLOAD, "id", GROUP, "project");
    final int exitCode = fossologySshConnector.runInFossologyViaSsh(command, inputStream, outputStream);
    final long uploadId = FossologyUploader.parseResultUploadId(outputStream.getContent());
    System.out.println("uploaded as " + uploadId);
    assertThat("Send to fossology failed: " + outputStream.getContent(), exitCode, is(0));
    assertThat("bad uploadId received: " + outputStream.getContent(), uploadId, is(greaterThan(0L)));
    int i = 0;
    while (++i < 60) {
        ByteArrayOutputStream osget = new ByteArrayOutputStream();
        final String commandGet = String.format(FossologyUploader.FOSSOLOGY_COMMAND_GET_STATUS, uploadId, GROUP);
        final int exitCodeGet = fossologySshConnector.runInFossologyViaSsh(commandGet, osget);
        if (exitCodeGet != 0) {
            fail("check status script is broken");
            break;
        }
        final String outputget = new String(osget.toByteArray());
        final FossologyStatus status = fossologyUploader.parseResultStatus(outputget);
        System.out.println("status is " + status + ", try changing it from FOSSology");
        if (status.equals(FossologyStatus.CLOSED)) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            fail("interrupted");
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CapturerOutputStream(org.eclipse.sw360.fossology.ssh.FossologyUploader.CapturerOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) FossologyHostFingerPrint(org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with FossologyStatus

use of org.eclipse.sw360.datahandler.thrift.components.FossologyStatus in project sw360portal by sw360.

the class FossologyUploader method parseResultStatus.

protected FossologyStatus parseResultStatus(String output) {
    final Pattern pattern = Pattern.compile("status=(\\w*)");
    final Matcher matcher = pattern.matcher(output);
    if (matcher.find()) {
        try {
            return FossologyStatus.valueOf(matcher.group(1));
        } catch (Exception e) {
            log.error("fossology output parser caught exception: " + e.getMessage(), e);
        }
    }
    log.error("cannot parse output from fossology check status: '" + output + "'");
    return FossologyStatus.CONNECTION_FAILED;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) IOException(java.io.IOException) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Aggregations

FossologyStatus (org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)14 Release (org.eclipse.sw360.datahandler.thrift.components.Release)8 Test (org.junit.Test)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 OutputStream (java.io.OutputStream)2 Map (java.util.Map)2 TEnumToString (org.eclipse.sw360.datahandler.TEnumToString)2 JSONArray (com.liferay.portal.kernel.json.JSONArray)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 TException (org.apache.thrift.TException)1 CommonUtils.nullToEmptyMap (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyMap)1