use of org.apache.commons.httpclient.methods.DeleteMethod in project zeppelin by apache.
the class NotebookSecurityRestApiTest method deleteNoteForUser.
private void deleteNoteForUser(String noteId, String user, String pwd) throws IOException {
DeleteMethod delete = httpDelete(("/notebook/" + noteId), user, pwd);
assertThat("Test delete method:", delete, isAllowed());
delete.releaseConnection();
// make sure note is deleted
if (!noteId.isEmpty()) {
Note deletedNote = ZeppelinServer.notebook.getNote(noteId);
assertNull("Deleted note should be null", deletedNote);
}
}
use of org.apache.commons.httpclient.methods.DeleteMethod in project zeppelin by apache.
the class ZeppelinRestApiTest method testJobs.
@Test
public void testJobs() throws InterruptedException, IOException {
// create a note and a paragraph
Note note = ZeppelinServer.notebook.createNote(anonymous);
note.setName("note for run test");
Paragraph paragraph = note.addParagraph(AuthenticationInfo.ANONYMOUS);
paragraph.setText("%md This is test paragraph.");
Map config = paragraph.getConfig();
config.put("enabled", true);
paragraph.setConfig(config);
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;
}
}
String jsonRequest = "{\"cron\":\"* * * * * ?\" }";
// right cron expression but not exist note.
PostMethod postCron = httpPost("/notebook/cron/notexistnote", jsonRequest);
assertThat("", postCron, isNotFound());
postCron.releaseConnection();
// right cron expression.
postCron = httpPost("/notebook/cron/" + note.getId(), jsonRequest);
assertThat("", postCron, isAllowed());
postCron.releaseConnection();
Thread.sleep(1000);
// wrong cron expression.
jsonRequest = "{\"cron\":\"a * * * * ?\" }";
postCron = httpPost("/notebook/cron/" + note.getId(), jsonRequest);
assertThat("", postCron, isBadRequest());
postCron.releaseConnection();
Thread.sleep(1000);
// remove cron job.
DeleteMethod deleteCron = httpDelete("/notebook/cron/" + note.getId());
assertThat("", deleteCron, isAllowed());
deleteCron.releaseConnection();
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
use of org.apache.commons.httpclient.methods.DeleteMethod in project zeppelin by apache.
the class ZeppelinRestApiTest method testDeleteParagraph.
@Test
public void testDeleteParagraph() throws IOException {
Note note = ZeppelinServer.notebook.createNote(anonymous);
Paragraph p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
p.setTitle("title1");
p.setText("text1");
note.persist(anonymous);
DeleteMethod delete = httpDelete("/notebook/" + note.getId() + "/paragraph/" + p.getId());
assertThat("Test delete method: ", delete, isAllowed());
delete.releaseConnection();
Note retrNote = ZeppelinServer.notebook.getNote(note.getId());
Paragraph retrParagrah = retrNote.getParagraph(p.getId());
assertNull("paragraph should be deleted", retrParagrah);
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
use of org.apache.commons.httpclient.methods.DeleteMethod in project tdi-studio-se by Talend.
the class MDMTransaction method rollback.
public void rollback() throws IOException {
HttpClient client = new HttpClient();
client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
HttpMethod method = new DeleteMethod(url + "/" + id);
method.setDoAuthentication(true);
try {
//$NON-NLS-1$ //$NON-NLS-2$
method.setRequestHeader("Cookie", getStickySession() + "=" + sessionId);
client.executeMethod(method);
} catch (HttpException e) {
throw e;
} catch (IOException e) {
throw e;
} finally {
method.releaseConnection();
}
int statuscode = method.getStatusCode();
if (statuscode >= 400) {
throw new MDMTransactionException("Rollback failed. The rollback operation has returned the code " + statuscode + ".");
}
}
use of org.apache.commons.httpclient.methods.DeleteMethod in project zm-mailbox by Zimbra.
the class ElasticSearchIndexTest method cleanupForIndexStore.
@Override
protected void cleanupForIndexStore() {
String key = testAcct.getId();
String indexUrl = String.format("%s%s/", LC.zimbra_index_elasticsearch_url_base.value(), key);
HttpMethod method = new DeleteMethod(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);
}
}
Aggregations