HDDS-575. LoadExistingContainers should be moved to SCMContainerManager from ContainerStateManager. Contributed by Mukul Kumar Singh.
This commit is contained in:
parent
273cc2d4e9
commit
f362037527
|
@ -158,46 +158,6 @@ public class ContainerStateManager implements Closeable {
|
|||
lastUsedMap = new ConcurrentHashMap<>();
|
||||
containerCount = new AtomicLong(0);
|
||||
containers = new ContainerStateMap();
|
||||
loadExistingContainers(containerManager, pipelineSelector);
|
||||
}
|
||||
|
||||
private void loadExistingContainers(ContainerManager containerManager,
|
||||
PipelineSelector pipelineSelector) {
|
||||
|
||||
List<ContainerInfo> containerList;
|
||||
try {
|
||||
containerList = containerManager.listContainer(0, Integer.MAX_VALUE);
|
||||
|
||||
// if there are no container to load, let us return.
|
||||
if (containerList == null || containerList.size() == 0) {
|
||||
LOG.info("No containers to load for this cluster.");
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (!e.getMessage().equals("No container exists in current db")) {
|
||||
LOG.error("Could not list the containers", e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
long maxID = 0;
|
||||
for (ContainerInfo container : containerList) {
|
||||
containers.addContainer(container);
|
||||
pipelineSelector.addContainerToPipeline(
|
||||
container.getPipelineID(), container.getContainerID());
|
||||
|
||||
if (maxID < container.getContainerID()) {
|
||||
maxID = container.getContainerID();
|
||||
}
|
||||
|
||||
containerCount.set(maxID);
|
||||
}
|
||||
} catch (SCMException ex) {
|
||||
LOG.error("Unable to create a container information. ", ex);
|
||||
// Fix me, what is the proper shutdown procedure for SCM ??
|
||||
// System.exit(1) // Should we exit here?
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -284,6 +244,15 @@ public class ContainerStateManager implements Closeable {
|
|||
LifeCycleEvent.CLEANUP);
|
||||
}
|
||||
|
||||
public void addExistingContainer(ContainerInfo containerInfo)
|
||||
throws SCMException {
|
||||
containers.addContainer(containerInfo);
|
||||
long containerID = containerInfo.getContainerID();
|
||||
if (containerCount.get() < containerID) {
|
||||
containerCount.set(containerID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* allocates a new container based on the type, replication etc.
|
||||
*
|
||||
|
|
|
@ -146,6 +146,38 @@ public class SCMContainerManager implements ContainerManager {
|
|||
containerLeaseManager = new LeaseManager<>("ContainerCreation",
|
||||
containerCreationLeaseTimeout);
|
||||
containerLeaseManager.start();
|
||||
loadExistingContainers();
|
||||
}
|
||||
|
||||
private void loadExistingContainers() {
|
||||
|
||||
List<ContainerInfo> containerList;
|
||||
try {
|
||||
containerList = listContainer(0, Integer.MAX_VALUE);
|
||||
|
||||
// if there are no container to load, let us return.
|
||||
if (containerList == null || containerList.size() == 0) {
|
||||
LOG.info("No containers to load for this cluster.");
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (!e.getMessage().equals("No container exists in current db")) {
|
||||
LOG.error("Could not list the containers", e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
for (ContainerInfo container : containerList) {
|
||||
containerStateManager.addExistingContainer(container);
|
||||
pipelineSelector.addContainerToPipeline(
|
||||
container.getPipelineID(), container.getContainerID());
|
||||
}
|
||||
} catch (SCMException ex) {
|
||||
LOG.error("Unable to create a container information. ", ex);
|
||||
// Fix me, what is the proper shutdown procedure for SCM ??
|
||||
// System.exit(1) // Should we exit here?
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue