protected void disposeAllContainers() {
   ServiceResponse<KieContainerResourceList> response = client.listContainers();
   Assert.assertEquals(ServiceResponse.ResponseType.SUCCESS, response.getType());
   List<KieContainerResource> containers = response.getResult().getContainers();
   if (containers != null) {
     for (KieContainerResource container : containers) {
       client.disposeContainer(container.getContainerId());
     }
   }
 }
 public ServiceResponse<KieContainerResource> createContainer(
     String containerId, KieContainerResource container) {
   if (container == null || container.getReleaseId() == null) {
     logger.error("Error creating container. Release Id is null: " + container);
     return new ServiceResponse<KieContainerResource>(
         ServiceResponse.ResponseType.FAILURE,
         "Failed to create container " + containerId + ". Release Id is null: " + container + ".");
   }
   ReleaseId releaseId = container.getReleaseId();
   try {
     KieContainerInstance ci = new KieContainerInstance(containerId, KieContainerStatus.CREATING);
     KieContainerInstance previous = null;
     // have to synchronize on the ci or a concurrent call to dispose may create inconsistencies
     synchronized (ci) {
       if ((previous = context.addIfDoesntExist(containerId, ci)) == null) {
         try {
           KieServices ks = KieServices.Factory.get();
           InternalKieContainer kieContainer =
               (InternalKieContainer) ks.newKieContainer(releaseId);
           if (kieContainer != null) {
             ci.setKieContainer(kieContainer);
             ci.getResource().setStatus(KieContainerStatus.STARTED);
             return new ServiceResponse<KieContainerResource>(
                 ServiceResponse.ResponseType.SUCCESS,
                 "Container "
                     + containerId
                     + " successfully deployed with module "
                     + releaseId
                     + ".",
                 ci.getResource());
           } else {
             ci.getResource().setStatus(KieContainerStatus.FAILED);
             return new ServiceResponse<KieContainerResource>(
                 ServiceResponse.ResponseType.FAILURE,
                 "Failed to create container " + containerId + " with module " + releaseId + ".");
           }
         } catch (Exception e) {
           logger.error(
               "Error creating container '" + containerId + "' for module '" + releaseId + "'", e);
           ci.getResource().setStatus(KieContainerStatus.FAILED);
           return new ServiceResponse<KieContainerResource>(
               ServiceResponse.ResponseType.FAILURE,
               "Failed to create container "
                   + containerId
                   + " with module "
                   + releaseId
                   + ": "
                   + e.getClass().getName()
                   + ": "
                   + e.getMessage());
         } finally {
           persistContainer(ci);
         }
       } else {
         return new ServiceResponse<KieContainerResource>(
             ServiceResponse.ResponseType.FAILURE,
             "Container " + containerId + " already exists.",
             previous.getResource());
       }
     }
   } catch (Exception e) {
     logger.error(
         "Error creating container '" + containerId + "' for module '" + releaseId + "'", e);
     return new ServiceResponse<KieContainerResource>(
         ServiceResponse.ResponseType.FAILURE,
         "Error creating container "
             + containerId
             + " with module "
             + releaseId
             + ": "
             + e.getClass().getName()
             + ": "
             + e.getMessage());
   }
 }