test_class.declarator: AZURE_CLOUD_ID = 20
test_class.modifier: private static final
test_class.original_string: private static final long AZURE_CLOUD_ID = 20;
test_class.type: long
test_class.var_name: AZURE_CLOUD_ID
test_class.declarator: OPENSTACK_CLOUD_ID = 21
test_class.modifier: private static final
test_class.original_string: private static final long OPENSTACK_CLOUD_ID = 21;
test_class.type: long
test_class.var_name: OPENSTACK_CLOUD_ID
test_class.declarator: GOOGLE_CLOUD_ID = 22
test_class.modifier: private static final
test_class.original_string: private static final long GOOGLE_CLOUD_ID = 22;
test_class.type: long
test_class.var_name: GOOGLE_CLOUD_ID
test_class.declarator: AZURE_CLOUD_LOCATION = "azure-eastus"
test_class.modifier: private static final
test_class.original_string: private static final String AZURE_CLOUD_LOCATION = "azure-eastus";
test_class.type: String
test_class.var_name: AZURE_CLOUD_LOCATION
test_class.declarator: OPENSTACK_CLOUD_LOCATION = "openstack-dal"
test_class.modifier: private static final
test_class.original_string: private static final String OPENSTACK_CLOUD_LOCATION = "openstack-dal";
test_class.type: String
test_class.var_name: OPENSTACK_CLOUD_LOCATION
test_class.declarator: GOOGLE_CLOUD_LOCATION = "google-westcoast"
test_class.modifier: private static final
test_class.original_string: private static final String GOOGLE_CLOUD_LOCATION = "google-westcoast";
test_class.type: String
test_class.var_name: GOOGLE_CLOUD_LOCATION
test_class.declarator: AZURE_SUBSCRIPTION_ID = "azure-sub1"
test_class.modifier: private static final
test_class.original_string: private static final String AZURE_SUBSCRIPTION_ID = "azure-sub1";
test_class.type: String
test_class.var_name: AZURE_SUBSCRIPTION_ID
test_class.declarator: OPENSTACK_SUBSCRIPTION_ID = "openstack-tenant1"
test_class.modifier: private static final
test_class.original_string: private static final String OPENSTACK_SUBSCRIPTION_ID = "openstack-tenant1";
test_class.type: String
test_class.var_name: OPENSTACK_SUBSCRIPTION_ID
test_class.declarator: GOOGLE_SUBSCRIPTION_ID = "google-sub1"
test_class.modifier: private static final
test_class.original_string: private static final String GOOGLE_SUBSCRIPTION_ID = "google-sub1";
test_class.type: String
test_class.var_name: GOOGLE_SUBSCRIPTION_ID
test_class.declarator: ENV_NS_PATH = "/org1/a1/e1"
test_class.modifier: private static final
test_class.original_string: private static final String ENV_NS_PATH = "/org1/a1/e1";
test_class.type: String
test_class.var_name: ENV_NS_PATH
test_class.declarator: cmsVarCapacityManagement
test_class.modifier: private
test_class.original_string: private CmsVar cmsVarCapacityManagement;
test_class.type: CmsVar
test_class.var_name: cmsVarCapacityManagement
test_class.declarator: azureCloud
test_class.modifier: private
test_class.original_string: private CmsCI azureCloud;
test_class.type: CmsCI
test_class.var_name: azureCloud
test_class.declarator: openstackCloud
test_class.modifier: private
test_class.original_string: private CmsCI openstackCloud;
test_class.type: CmsCI
test_class.var_name: openstackCloud
test_class.declarator: googleCloud
test_class.modifier: private
test_class.original_string: private CmsCI googleCloud;
test_class.type: CmsCI
test_class.var_name: googleCloud
test_class.declarator: bomCIs
test_class.modifier: private
test_class.original_string: private ArrayList<CmsRfcCI> bomCIs;
test_class.type: ArrayList<CmsRfcCI>
test_class.var_name: bomCIs
test_class.declarator: bomRels
test_class.modifier: private
test_class.original_string: private ArrayList<CmsRfcRelation > bomRels;
test_class.type: ArrayList<CmsRfcRelation >
test_class.var_name: bomRels
test_class.declarator: capacityProcessor = new CapacityProcessor()
test_class.modifier: private
test_class.original_string: private CapacityProcessor capacityProcessor = new CapacityProcessor();
test_class.type: CapacityProcessor
test_class.var_name: capacityProcessor
test_class.declarator: cmProcessorMock
test_class.modifier: private
test_class.original_string: private CmsCmProcessor cmProcessorMock;
test_class.type: CmsCmProcessor
test_class.var_name: cmProcessorMock
test_class.declarator: tektonClientMock = Mockito.mock(TektonClient.class)
test_class.modifier: private
test_class.original_string: private TektonClient tektonClientMock = Mockito.mock(TektonClient.class);
test_class.type: TektonClient
test_class.var_name: tektonClientMock
test_class.file: cmsdal/src/test/java/com/oneops/capacity/CapacityProcessorTest.java
test_class.identifier: CapacityProcessorTest
test_case.body: @Test
      public void testReserve() throws ReservationException {
          CmsDeployment deployment = new CmsDeployment();
          long deploymentId = 1L;
          long releaseId = 1L;
          String createdBy = "user1";
          deployment.setReleaseId(deploymentId);
          deployment.setDeploymentId(releaseId);
          deployment.setNsPath(ENV_NS_PATH + "/bom");
          deployment.setCreatedBy(createdBy);
  
  
          // Should reserve.
          bomCIs.clear();
          bomRels.clear();
          createComputeRfc(1L, "update", "M", azureCloud);
          createComputeRfc(2L, "add", "M", azureCloud);
          createComputeRfc(3L, "delete", "M", azureCloud);
          createComputeRfc(4L, "add", "M", azureCloud);
          createComputeRfc(5L, "add", "mem-L", azureCloud);
          createComputeRfc(6L, "add", "M", openstackCloud);
          createRfc(7L, "add", "bom.oneops.1.Lb", azureCloud);
          createRfc(8L, "update", "bom.oneops.1.Lb", azureCloud);
          createRfc(9L, "add", "bom.oneops.1.Lb", openstackCloud);
  
          Map<String, Map<String, Integer>> expectedCapacity = new HashMap<>();
          Map<String, Integer> resources = new HashMap<>();
          resources.put("Dv2", 4);
          resources.put("DSv3", 6);
          resources.put("vm", 3);
          resources.put("nic", 3);
          resources.put("lb", 1);
          expectedCapacity.put(AZURE_CLOUD_LOCATION + ":" + AZURE_SUBSCRIPTION_ID, resources);
          resources = new HashMap<>();
          resources.put("core", 4);
          resources.put("vm", 1);
          expectedCapacity.put(OPENSTACK_CLOUD_LOCATION + ":" + OPENSTACK_SUBSCRIPTION_ID, resources);
          ArgumentCaptor<HashMap> argument = ArgumentCaptor.forClass(HashMap.class);
  
          capacityProcessor.reserveCapacityForDeployment(deployment);
          Mockito.verify(tektonClientMock, Mockito.times(1))
                  .reserveQuota(argument.capture(), Mockito.eq(ENV_NS_PATH), Mockito.eq(createdBy));
  
          Assert.assertEquals(argument.getValue(), expectedCapacity);
  
          // Should not reserve - update RFCs only.
          bomCIs.clear();
          bomRels.clear();
          createComputeRfc(1L, "update", "M", azureCloud);
  
          capacityProcessor.reserveCapacityForDeployment(deployment);
          Mockito.verify(tektonClientMock, Mockito.times(1))
                  .reserveQuota(Mockito.anyMap(), Mockito.eq(ENV_NS_PATH), Mockito.eq(createdBy));
  
          // Should not reserve - no mapping for cloud provider.
          bomCIs.clear();
          bomRels.clear();
          createComputeRfc(1L, "add", "M", googleCloud);
          createComputeRfc(2L, "update", "M", googleCloud);
  
          capacityProcessor.reserveCapacityForDeployment(deployment);
          Mockito.verify(tektonClientMock, Mockito.times(1))
                  .reserveQuota(Mockito.anyMap(), Mockito.eq(ENV_NS_PATH), Mockito.eq(createdBy));
      }
test_case.class_method_signature: CapacityProcessorTest.testReserve()
test_case.full_signature: @Test public void testReserve()
test_case.identifier: testReserve
test_case.invocations: setReleaseId setDeploymentId setNsPath setCreatedBy clear clear createComputeRfc createComputeRfc createComputeRfc createComputeRfc createComputeRfc createComputeRfc createRfc createRfc createRfc put put put put put put put put put forClass reserveCapacityForDeployment reserveQuota verify times capture eq eq assertEquals getValue clear clear createComputeRfc reserveCapacityForDeployment reserveQuota verify times anyMap eq eq clear clear createComputeRfc createComputeRfc reserveCapacityForDeployment reserveQuota verify times anyMap eq eq
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testReserve()
focal_class.declarator: logger = Logger.getLogger(CapacityProcessor.class)
focal_class.modifier: private static
focal_class.original_string: private static Logger logger = Logger.getLogger(CapacityProcessor.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: CAPACITY_MANAGEMENT_VAR_NAME = "CAPACITY_MANAGEMENT"
focal_class.modifier: static final
focal_class.original_string: static final String CAPACITY_MANAGEMENT_VAR_NAME = "CAPACITY_MANAGEMENT";
focal_class.type: String
focal_class.var_name: CAPACITY_MANAGEMENT_VAR_NAME
focal_class.declarator: PROVIDER_MAPPINGS_CMS_VAR_NAME = "CLOUD_PROVIDER_MAPPINGS"
focal_class.modifier: static final
focal_class.original_string: static final String PROVIDER_MAPPINGS_CMS_VAR_NAME = "CLOUD_PROVIDER_MAPPINGS";
focal_class.type: String
focal_class.var_name: PROVIDER_MAPPINGS_CMS_VAR_NAME
focal_class.declarator: cmProcessor
focal_class.modifier: private
focal_class.original_string: private CmsCmProcessor cmProcessor;
focal_class.type: CmsCmProcessor
focal_class.var_name: cmProcessor
focal_class.declarator: rfcProcessor
focal_class.modifier: private
focal_class.original_string: private CmsRfcProcessor rfcProcessor;
focal_class.type: CmsRfcProcessor
focal_class.var_name: rfcProcessor
focal_class.declarator: tektonClient
focal_class.modifier: private
focal_class.original_string: private TektonClient tektonClient;
focal_class.type: TektonClient
focal_class.var_name: tektonClient
focal_class.declarator: gson = new Gson()
focal_class.modifier: private
focal_class.original_string: private Gson gson = new Gson();
focal_class.type: Gson
focal_class.var_name: gson
focal_class.file: cmsdal/src/main/java/com/oneops/capacity/CapacityProcessor.java
focal_class.identifier: CapacityProcessor
focal_class.class_method_signature: CapacityProcessor.setCmProcessor(CmsCmProcessor cmProcessor)
focal_class.full_signature: public void setCmProcessor(CmsCmProcessor cmProcessor)
focal_class.identifier: setCmProcessor
focal_class.modifiers: public
focal_class.parameters: (CmsCmProcessor cmProcessor)
focal_class.return: void
focal_class.signature: void setCmProcessor(CmsCmProcessor cmProcessor)
focal_class.class_method_signature: CapacityProcessor.setRfcProcessor(CmsRfcProcessor rfcProcessor)
focal_class.full_signature: public void setRfcProcessor(CmsRfcProcessor rfcProcessor)
focal_class.identifier: setRfcProcessor
focal_class.modifiers: public
focal_class.parameters: (CmsRfcProcessor rfcProcessor)
focal_class.return: void
focal_class.signature: void setRfcProcessor(CmsRfcProcessor rfcProcessor)
focal_class.class_method_signature: CapacityProcessor.setTektonClient(TektonClient tektonClient)
focal_class.full_signature: public void setTektonClient(TektonClient tektonClient)
focal_class.identifier: setTektonClient
focal_class.modifiers: public
focal_class.parameters: (TektonClient tektonClient)
focal_class.return: void
focal_class.signature: void setTektonClient(TektonClient tektonClient)
focal_class.class_method_signature: CapacityProcessor.isCapacityManagementEnabled(String nsPath)
focal_class.full_signature: public boolean isCapacityManagementEnabled(String nsPath)
focal_class.identifier: isCapacityManagementEnabled
focal_class.modifiers: public
focal_class.parameters: (String nsPath)
focal_class.return: boolean
focal_class.signature: boolean isCapacityManagementEnabled(String nsPath)
focal_class.class_method_signature: CapacityProcessor.estimateCapacity(String nsPath, Collection<CmsRfcCI> cis, Collection<CmsRfcRelation> deployedToRels)
focal_class.full_signature: public CapacityEstimate estimateCapacity(String nsPath, Collection<CmsRfcCI> cis, Collection<CmsRfcRelation> deployedToRels)
focal_class.identifier: estimateCapacity
focal_class.modifiers: public
focal_class.parameters: (String nsPath, Collection<CmsRfcCI> cis, Collection<CmsRfcRelation> deployedToRels)
focal_class.return: CapacityEstimate
focal_class.signature: CapacityEstimate estimateCapacity(String nsPath, Collection<CmsRfcCI> cis, Collection<CmsRfcRelation> deployedToRels)
focal_class.class_method_signature: CapacityProcessor.reserveCapacityForDeployment(CmsDeployment deployment)
focal_class.full_signature: public void reserveCapacityForDeployment(CmsDeployment deployment)
focal_class.identifier: reserveCapacityForDeployment
focal_class.modifiers: public
focal_class.parameters: (CmsDeployment deployment)
focal_class.return: void
focal_class.signature: void reserveCapacityForDeployment(CmsDeployment deployment)
focal_class.class_method_signature: CapacityProcessor.discardCapacityForDeployment(CmsDeployment deployment)
focal_class.full_signature: public void discardCapacityForDeployment(CmsDeployment deployment)
focal_class.identifier: discardCapacityForDeployment
focal_class.modifiers: public
focal_class.parameters: (CmsDeployment deployment)
focal_class.return: void
focal_class.signature: void discardCapacityForDeployment(CmsDeployment deployment)
focal_class.class_method_signature: CapacityProcessor.commitCapacity(CmsWorkOrder workOrder)
focal_class.full_signature: public void commitCapacity(CmsWorkOrder workOrder)
focal_class.identifier: commitCapacity
focal_class.modifiers: public
focal_class.parameters: (CmsWorkOrder workOrder)
focal_class.return: void
focal_class.signature: void commitCapacity(CmsWorkOrder workOrder)
focal_class.class_method_signature: CapacityProcessor.releaseCapacity(CmsWorkOrder workOrder)
focal_class.full_signature: public void releaseCapacity(CmsWorkOrder workOrder)
focal_class.identifier: releaseCapacity
focal_class.modifiers: public
focal_class.parameters: (CmsWorkOrder workOrder)
focal_class.return: void
focal_class.signature: void releaseCapacity(CmsWorkOrder workOrder)
focal_class.class_method_signature: CapacityProcessor.getReservationNsPath(String fullNsPath)
focal_class.full_signature: private String getReservationNsPath(String fullNsPath)
focal_class.identifier: getReservationNsPath
focal_class.modifiers: private
focal_class.parameters: (String fullNsPath)
focal_class.return: String
focal_class.signature: String getReservationNsPath(String fullNsPath)
focal_class.class_method_signature: CapacityProcessor.getCloudProviderMappings()
focal_class.full_signature: private Map<String, Object> getCloudProviderMappings()
focal_class.identifier: getCloudProviderMappings
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: Map<String, Object>
focal_class.signature: Map<String, Object> getCloudProviderMappings()
focal_class.class_method_signature: CapacityProcessor.getDeployedToCloudInfoMap(Collection<CmsRfcRelation> deployedToRels)
focal_class.full_signature: private Map<Long, CloudInfo> getDeployedToCloudInfoMap(Collection<CmsRfcRelation> deployedToRels)
focal_class.identifier: getDeployedToCloudInfoMap
focal_class.modifiers: private
focal_class.parameters: (Collection<CmsRfcRelation> deployedToRels)
focal_class.return: Map<Long, CloudInfo>
focal_class.signature: Map<Long, CloudInfo> getDeployedToCloudInfoMap(Collection<CmsRfcRelation> deployedToRels)
focal_class.class_method_signature: CapacityProcessor.getDeployedToCloudInfo(long cloudCiId)
focal_class.full_signature: private CloudInfo getDeployedToCloudInfo(long cloudCiId)
focal_class.identifier: getDeployedToCloudInfo
focal_class.modifiers: private
focal_class.parameters: (long cloudCiId)
focal_class.return: CloudInfo
focal_class.signature: CloudInfo getDeployedToCloudInfo(long cloudCiId)
focal_class.class_method_signature: CapacityProcessor.getDeployedToCloudInfo(CmsCI cloud)
focal_class.full_signature: private CloudInfo getDeployedToCloudInfo(CmsCI cloud)
focal_class.identifier: getDeployedToCloudInfo
focal_class.modifiers: private
focal_class.parameters: (CmsCI cloud)
focal_class.return: CloudInfo
focal_class.signature: CloudInfo getDeployedToCloudInfo(CmsCI cloud)
focal_class.class_method_signature: CapacityProcessor.getCapacityForCis(Collection<CmsRfcCI> cis,
                                                                  Collection<CmsRfcRelation> deployedToRels,
                                                                  Map<Long, CloudInfo> cloudInfoMap,
                                                                  Map<String, Object> mappings)
focal_class.full_signature: private Map<String, Map<String, Integer>> getCapacityForCis(Collection<CmsRfcCI> cis,
                                                                  Collection<CmsRfcRelation> deployedToRels,
                                                                  Map<Long, CloudInfo> cloudInfoMap,
                                                                  Map<String, Object> mappings)
focal_class.identifier: getCapacityForCis
focal_class.modifiers: private
focal_class.parameters: (Collection<CmsRfcCI> cis,
                                                                  Collection<CmsRfcRelation> deployedToRels,
                                                                  Map<Long, CloudInfo> cloudInfoMap,
                                                                  Map<String, Object> mappings)
focal_class.return: Map<String, Map<String, Integer>>
focal_class.signature: Map<String, Map<String, Integer>> getCapacityForCis(Collection<CmsRfcCI> cis,
                                                                  Collection<CmsRfcRelation> deployedToRels,
                                                                  Map<Long, CloudInfo> cloudInfoMap,
                                                                  Map<String, Object> mappings)
focal_class.class_method_signature: CapacityProcessor.getCapacityForCi(CmsRfcCI rfcCi, CloudInfo cloudInfo, Map<String, Object> mappings)
focal_class.full_signature: private Map<String, Integer> getCapacityForCi(CmsRfcCI rfcCi, CloudInfo cloudInfo, Map<String, Object> mappings)
focal_class.identifier: getCapacityForCi
focal_class.modifiers: private
focal_class.parameters: (CmsRfcCI rfcCi, CloudInfo cloudInfo, Map<String, Object> mappings)
focal_class.return: Map<String, Integer>
focal_class.signature: Map<String, Integer> getCapacityForCi(CmsRfcCI rfcCi, CloudInfo cloudInfo, Map<String, Object> mappings)
focal_class.class_method_signature: CapacityProcessor.deleteReservations(String nsPath)
focal_class.full_signature: private void deleteReservations(String nsPath)
focal_class.identifier: deleteReservations
focal_class.modifiers: private
focal_class.parameters: (String nsPath)
focal_class.return: void
focal_class.signature: void deleteReservations(String nsPath)
focal_class.class_method_signature: CapacityProcessor.capacityShortageMessage(Map<String, String> info, Map<Long, CloudInfo> cloudInfo, String prefix)
focal_class.full_signature: private String capacityShortageMessage(Map<String, String> info, Map<Long, CloudInfo> cloudInfo, String prefix)
focal_class.identifier: capacityShortageMessage
focal_class.modifiers: private
focal_class.parameters: (Map<String, String> info, Map<Long, CloudInfo> cloudInfo, String prefix)
focal_class.return: String
focal_class.signature: String capacityShortageMessage(Map<String, String> info, Map<Long, CloudInfo> cloudInfo, String prefix)
focal_method.body: public void reserveCapacityForDeployment(CmsDeployment deployment) {
          String nsPath = deployment.getNsPath();
          if (!isCapacityManagementEnabled(nsPath)) return;
  
          // Just in case dump any reservation "leftovers".
          deleteReservations(getReservationNsPath(nsPath));
  
          Map<String, Object> mappings = getCloudProviderMappings();
          if (mappings == null) return;
  
          // Get capacity increase
          long releaseId = deployment.getReleaseId();
          List<CmsRfcCI> cis = rfcProcessor.getRfcCIBy3(releaseId, true, null);
          List<CmsRfcRelation> deployedToRels = rfcProcessor.getRfcRelationByReleaseAndClassNoAttrs(releaseId, null, "DeployedTo");
  
          Map<Long, CloudInfo> deployedToCloudInfoMap = getDeployedToCloudInfoMap(deployedToRels);
          List<CmsRfcCI> addCIs = cis.stream().filter(ci -> ci.getRfcAction().equals("add")).collect(toList());
          Map<String, Map<String, Integer>> capacity = getCapacityForCis(addCIs, deployedToRels, deployedToCloudInfoMap, mappings);
  
          if (!capacity.isEmpty()) {
              try {
                  tektonClient.reserveQuota(capacity, getReservationNsPath(nsPath), deployment.getCreatedBy());
              } catch (ReservationException exception) {
                  Map<String, String> info = exception.getInfo();
                  String message = info == null ? exception.getMessage() : capacityShortageMessage(info, deployedToCloudInfoMap, "Failed to reserve capacity:\n");
                  throw new RuntimeException(message);
              }
          }
      }
focal_method.class_method_signature: CapacityProcessor.reserveCapacityForDeployment(CmsDeployment deployment)
focal_method.full_signature: public void reserveCapacityForDeployment(CmsDeployment deployment)
focal_method.identifier: reserveCapacityForDeployment
focal_method.invocations: getNsPath isCapacityManagementEnabled deleteReservations getReservationNsPath getCloudProviderMappings getReleaseId getRfcCIBy3 getRfcRelationByReleaseAndClassNoAttrs getDeployedToCloudInfoMap collect filter stream equals getRfcAction toList getCapacityForCis isEmpty reserveQuota getReservationNsPath getCreatedBy getInfo getMessage capacityShortageMessage
focal_method.modifiers: public
focal_method.parameters: (CmsDeployment deployment)
focal_method.return: void
focal_method.signature: void reserveCapacityForDeployment(CmsDeployment deployment)