Search in sources :

Example 11 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project zm-mailbox by Zimbra.

the class TritonBlobStoreManager method deleteFromStore.

@Override
public boolean deleteFromStore(String locator, Mailbox mbox) throws IOException {
    HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
    DeleteMethod delete = new DeleteMethod(blobApiUrl + locator);
    delete.addRequestHeader(TritonHeaders.HASH_TYPE, hashType.toString());
    try {
        ZimbraLog.store.info("deleting %s", delete.getURI());
        int statusCode = HttpClientUtil.executeMethod(client, delete);
        if (statusCode == HttpStatus.SC_OK) {
            return true;
        } else {
            throw new IOException("unexpected return code during blob DELETE: " + delete.getStatusText());
        }
    } finally {
        delete.releaseConnection();
    }
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) HttpClient(org.apache.commons.httpclient.HttpClient) IOException(java.io.IOException)

Example 12 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project zm-mailbox by Zimbra.

the class ElasticSearchIndex method deleteIndex.

@Override
public void deleteIndex() {
    HttpMethod method = new DeleteMethod(ElasticSearchConnector.actualUrl(indexUrl));
    try {
        ElasticSearchConnector connector = new ElasticSearchConnector();
        int statusCode = connector.executeMethod(method);
        if (statusCode == HttpStatus.SC_OK) {
            boolean ok = connector.getBooleanAtJsonPath(new String[] { "ok" }, false);
            boolean acknowledged = connector.getBooleanAtJsonPath(new String[] { "acknowledged" }, false);
            if (!ok || !acknowledged) {
                ZimbraLog.index.debug("Delete index status ok=%b acknowledged=%b", ok, acknowledged);
            }
        } else {
            String error = connector.getStringAtJsonPath(new String[] { "error" });
            if (error != null && error.startsWith("IndexMissingException")) {
                ZimbraLog.index.debug("Unable to delete index for key=%s.  Index is missing", key);
            } else {
                ZimbraLog.index.error("Problem deleting index for key=%s error=%s", key, error);
            }
        }
    } catch (HttpException e) {
        ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
    } catch (IOException e) {
        ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
    }
    haveMappingInfo = false;
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 13 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project cloudstack by apache.

the class Action method executeDelete.

protected void executeDelete(final String uri) throws NeutronRestApiException {
    try {
        validateCredentials();
    } catch (NeutronInvalidCredentialsException e) {
        throw new NeutronRestApiException("Invalid credentials!", e);
    }
    NeutronRestFactory factory = NeutronRestFactory.getInstance();
    NeutronRestApi neutronRestApi = factory.getNeutronApi(DeleteMethod.class);
    DeleteMethod deleteMethod = (DeleteMethod) neutronRestApi.createMethod(url, uri);
    try {
        deleteMethod.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);
        String encodedCredentials = encodeCredentials();
        deleteMethod.setRequestHeader("Authorization", "Basic " + encodedCredentials);
        neutronRestApi.executeMethod(deleteMethod);
        if (deleteMethod.getStatusCode() != HttpStatus.SC_NO_CONTENT) {
            String errorMessage = responseToErrorMessage(deleteMethod);
            deleteMethod.releaseConnection();
            s_logger.error("Failed to update object : " + errorMessage);
            throw new NeutronRestApiException("Failed to create object : " + errorMessage);
        }
    } catch (NeutronRestApiException e) {
        s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e);
        throw new NeutronRestApiException("API call to Neutron Controller Failed", e);
    } finally {
        deleteMethod.releaseConnection();
    }
}
Also used : NeutronRestFactory(org.apache.cloudstack.network.opendaylight.api.NeutronRestFactory) NeutronRestApi(org.apache.cloudstack.network.opendaylight.api.NeutronRestApi) DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) NeutronInvalidCredentialsException(org.apache.cloudstack.network.opendaylight.api.NeutronInvalidCredentialsException) NeutronRestApiException(org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException)

Example 14 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project zeppelin by apache.

the class ZeppelinRestApiTest method testNoteJobs.

@Test
public void testNoteJobs() throws IOException, InterruptedException {
    LOG.info("testNoteJobs");
    // Create note to run test.
    Note note = ZeppelinServer.notebook.createNote(anonymous);
    assertNotNull("can't create new note", note);
    note.setName("note for run test");
    Paragraph paragraph = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    Map config = paragraph.getConfig();
    config.put("enabled", true);
    paragraph.setConfig(config);
    paragraph.setText("%md This is test paragraph.");
    note.persist(anonymous);
    String noteId = note.getId();
    note.runAll();
    // wait until job is finished or timeout.
    int timeout = 1;
    while (!paragraph.isTerminated()) {
        Thread.sleep(1000);
        if (timeout++ > 10) {
            LOG.info("testNoteJobs timeout job.");
            break;
        }
    }
    // Call Run note jobs REST API
    PostMethod postNoteJobs = httpPost("/notebook/job/" + noteId, "");
    assertThat("test note jobs run:", postNoteJobs, isAllowed());
    postNoteJobs.releaseConnection();
    // Call Stop note jobs REST API
    DeleteMethod deleteNoteJobs = httpDelete("/notebook/job/" + noteId);
    assertThat("test note stop:", deleteNoteJobs, isAllowed());
    deleteNoteJobs.releaseConnection();
    Thread.sleep(1000);
    // Call Run paragraph REST API
    PostMethod postParagraph = httpPost("/notebook/job/" + noteId + "/" + paragraph.getId(), "");
    assertThat("test paragraph run:", postParagraph, isAllowed());
    postParagraph.releaseConnection();
    Thread.sleep(1000);
    // Call Stop paragraph REST API
    DeleteMethod deleteParagraph = httpDelete("/notebook/job/" + noteId + "/" + paragraph.getId());
    assertThat("test paragraph stop:", deleteParagraph, isAllowed());
    deleteParagraph.releaseConnection();
    Thread.sleep(1000);
    //cleanup
    ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) PostMethod(org.apache.commons.httpclient.methods.PostMethod) Note(org.apache.zeppelin.notebook.Note) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 15 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project zeppelin by apache.

the class InterpreterRestApiTest method testSettingsCRUD.

@Test
public void testSettingsCRUD() throws IOException {
    // when: call create setting API
    String rawRequest = "{\"name\":\"md2\",\"group\":\"md\",\"properties\":{\"propname\":\"propvalue\"}," + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," + "\"dependencies\":[]," + "\"option\": { \"remote\": true, \"session\": false }}";
    JsonObject jsonRequest = gson.fromJson(rawRequest, JsonElement.class).getAsJsonObject();
    PostMethod post = httpPost("/interpreter/setting/", jsonRequest.toString());
    String postResponse = post.getResponseBodyAsString();
    LOG.info("testSettingCRUD create response\n" + post.getResponseBodyAsString());
    InterpreterSetting created = convertResponseToInterpreterSetting(postResponse);
    String newSettingId = created.getId();
    // then : call create setting API
    assertThat("test create method:", post, isAllowed());
    post.releaseConnection();
    // when: call read setting API
    GetMethod get = httpGet("/interpreter/setting/" + newSettingId);
    String getResponse = get.getResponseBodyAsString();
    LOG.info("testSettingCRUD get response\n" + getResponse);
    InterpreterSetting previouslyCreated = convertResponseToInterpreterSetting(getResponse);
    // then : read Setting API
    assertThat("Test get method:", get, isAllowed());
    assertEquals(newSettingId, previouslyCreated.getId());
    get.releaseConnection();
    // when: call update setting API
    jsonRequest.getAsJsonObject("properties").addProperty("propname2", "this is new prop");
    PutMethod put = httpPut("/interpreter/setting/" + newSettingId, jsonRequest.toString());
    LOG.info("testSettingCRUD update response\n" + put.getResponseBodyAsString());
    // then: call update setting API
    assertThat("test update method:", put, isAllowed());
    put.releaseConnection();
    // when: call delete setting API
    DeleteMethod delete = httpDelete("/interpreter/setting/" + newSettingId);
    LOG.info("testSettingCRUD delete response\n" + delete.getResponseBodyAsString());
    // then: call delete setting API
    assertThat("Test delete method:", delete, isAllowed());
    delete.releaseConnection();
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) PostMethod(org.apache.commons.httpclient.methods.PostMethod) JsonElement(com.google.gson.JsonElement) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JsonObject(com.google.gson.JsonObject) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Test(org.junit.Test)

Aggregations

DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)25 HttpClient (org.apache.commons.httpclient.HttpClient)9 IOException (java.io.IOException)8 HttpMethod (org.apache.commons.httpclient.HttpMethod)6 Test (org.junit.Test)6 HttpException (org.apache.commons.httpclient.HttpException)5 PostMethod (org.apache.commons.httpclient.methods.PostMethod)5 Note (org.apache.zeppelin.notebook.Note)5 GetMethod (org.apache.commons.httpclient.methods.GetMethod)4 PutMethod (org.apache.commons.httpclient.methods.PutMethod)4 Paragraph (org.apache.zeppelin.notebook.Paragraph)3 Account (com.zimbra.cs.account.Account)2 ElasticSearchConnector (com.zimbra.cs.index.elasticsearch.ElasticSearchConnector)2 URL (java.net.URL)2 Map (java.util.Map)2 Header (org.apache.commons.httpclient.Header)2 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)2 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1