Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve issue #48 #230

Merged
merged 4 commits into from
Dec 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ private void generateHistogram(Report report) {
metrics.setLatency(Histogram.convert(op.getCounter()));
}
}

@Override
public StateInfo[] getStateHistory() {
return stateHistory.getAllStates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@

import static com.intel.cosbench.driver.operator.Deleter.doDelete;

import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;

import com.intel.cosbench.api.storage.StorageException;
Expand Down Expand Up @@ -94,25 +99,82 @@ protected void operate(int idx, int all, Session session) {
session.getListener().onOperationCompleted(result);
}

public static void doDispose(String conName, Config config, Session session) {
public void doDispose(String conName, Config config, Session session) {
if (Thread.interrupted())
throw new AbortedException();

try {
session.getApi().deleteContainer(conName, config);
} catch (StorageInterruptedException sie) {
doLogErr(session.getLogger(), sie.getMessage(), sie);
throw new AbortedException();
} catch (StorageException se) {
String msg = "Error deleting container " + conName;
doLogWarn(session.getLogger(), msg);
// ignored
} catch (Exception e) {
doLogErr(session.getLogger(), "fail to perform clean operation " + conName, e);
throw new AgentException(); // mark error
}

/* no sample is provided for this operation */

boolean isEmpty = true;
boolean tryAgain = false;
do {
if(isEmpty) {
try {
session.getApi().deleteContainer(conName, config);
isEmpty = true;
tryAgain = false;
} catch (StorageInterruptedException sie) {
throw new AbortedException();
} catch (StorageException se) {
String msg = "Error deleting container " + conName;
doLogErr(session.getLogger(), msg,se);
if(isConflictException(session,se)) {
isEmpty = false;
tryAgain = true;
}else{
tryAgain = false;
}
} catch (Exception e) {
doLogErr(session.getLogger(), "fail to perform clean operation " + conName, e);
throw new AgentException(); // mark error
}
}else {
try{
for(String objName: getObjectsList(conName, config, session)) {
doDelete(conName, objName, config, session, this);
}
}catch(StorageException se) {
doLogErr(session.getLogger(), "fail to get : "+conName+" objects list ",se);
tryAgain = false;
}catch (IOException ioe) {
doLogErr(session.getLogger(), "fail to convert objects stream to string",ioe);
tryAgain = false;
}catch (Exception e) {
doLogErr(session.getLogger(), "unexpected error",e);
tryAgain = false;
}
isEmpty = true;
tryAgain = true;
}
}while(tryAgain == true);

}

private static String[] getObjectsList(String conName, Config config, Session session) throws IOException {
String[] objects = {};
StringWriter stringWriter = new StringWriter();
try {
IOUtils.copy(session.getApi().getList(conName, "", config), stringWriter);
}catch(StorageException se) {
throw se;
}catch (IOException e) {
throw e;
}
String objectString = stringWriter.toString();
objects = objectString.split("\n");
return objects;
}

private static boolean isConflictException(Session session, Exception e) {
if(e != null && e.getMessage() != null)
try{
if(409 == Integer.valueOf(e.getMessage().substring(9, 12))){
doLogDebug(session.getLogger(),"catch 409 error, will clean up the unempty container and try again");
return true;
}
}catch(NumberFormatException ne) {
ne.printStackTrace(); // mask ignore
return false;
}
return false;
}

}
2 changes: 1 addition & 1 deletion release/conf/controller.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[controller]
drivers = 1
log_level = DEBUG
log_level = INFO
log_file = log/system.log
archive_dir = archive

Expand Down
2 changes: 1 addition & 1 deletion release/conf/driver.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[driver]
log_level = DEBUG
log_level = INFO