Skip to content

Commit

Permalink
#670: Add a way to choose which instances to delete to BootstrapConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Apr 3, 2019
1 parent be20408 commit ea2e70b
Showing 2 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -16,8 +16,10 @@
package org.eclipse.leshan.server.bootstrap;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.leshan.SecurityMode;
@@ -29,6 +31,8 @@
@SuppressWarnings("serial")
public class BootstrapConfig implements Serializable {

public List<String> toDelete = new ArrayList<>();

public Map<Integer, ServerConfig> servers = new HashMap<>();

public Map<Integer, ServerSecurity> security = new HashMap<>();
Original file line number Diff line number Diff line change
@@ -114,26 +114,34 @@ public void run() {
}

protected void startBootstrap(BootstrapSession session, BootstrapConfig cfg) {
delete(session, cfg);
delete(session, cfg, new ArrayList<>(cfg.toDelete));
}

protected void delete(final BootstrapSession session, final BootstrapConfig cfg) {
protected void delete(final BootstrapSession session, final BootstrapConfig cfg, final List<String> pathToDelete) {
if (!pathToDelete.isEmpty()) {
// get next Security configuration
String path = pathToDelete.remove(0);

final BootstrapDeleteRequest deleteRequest = new BootstrapDeleteRequest();
send(session, deleteRequest, new ResponseCallback<BootstrapDeleteResponse>() {
@Override
public void onResponse(BootstrapDeleteResponse response) {
LOG.trace("Bootstrap delete {} return code {}", session.getEndpoint(), response.getCode());
List<Integer> instancesToWrite = new ArrayList<>(cfg.security.keySet());
writeSecurities(session, cfg, instancesToWrite);
}
}, new ErrorCallback() {
@Override
public void onError(Exception e) {
LOG.debug(String.format("Error during bootstrap delete '/' on %s", session.getEndpoint()), e);
sessionManager.failed(session, DELETE_FAILED, deleteRequest);
}
});
final BootstrapDeleteRequest deleteRequest = new BootstrapDeleteRequest(path);
send(session, deleteRequest, new ResponseCallback<BootstrapDeleteResponse>() {
@Override
public void onResponse(BootstrapDeleteResponse response) {
LOG.trace("Bootstrap delete {} return code {}", session.getEndpoint(), response.getCode());

delete(session, cfg, pathToDelete);
}
}, new ErrorCallback() {
@Override
public void onError(Exception e) {
LOG.debug(String.format("Error during bootstrap delete '/' on %s", session.getEndpoint()), e);
sessionManager.failed(session, DELETE_FAILED, deleteRequest);
}
});
} else {
// we are done, write the securities now
List<Integer> securityInstancesToWrite = new ArrayList<>(cfg.security.keySet());
writeSecurities(session, cfg, securityInstancesToWrite);
}
}

protected void writeSecurities(final BootstrapSession session, final BootstrapConfig cfg,

0 comments on commit ea2e70b

Please sign in to comment.