@Test public void testValidateMinResourcesRequired() throws Exception { factory = createKubernetesRuntimeFactory(null, null); FunctionDetails functionDetailsBase = createFunctionDetails(); try { factory.validateMinResourcesRequired(functionDetailsBase); } catch (Exception e) { fail(); } testMinResource(0.2, 2048L, false, null); testMinResource(0.05, 2048L, true, "Per instance CPU requested, 0.05, for function is less than the minimum required, 0.1"); testMinResource(0.2, 512L, true, "Per instance RAM requested, 512, for function is less than the minimum required, 1024"); testMinResource(0.05, 512L, true, "Per instance CPU requested, 0.05, for function is less than the minimum required, 0.1"); testMinResource(null, null, true, "Per instance CPU requested, 0.0, for function is less than the minimum required, 0.1"); testMinResource(0.2, null, true, "Per instance RAM requested, 0, for function is less than the minimum required, 1024"); testMinResource(0.05, null, true, "Per instance CPU requested, 0.05, for function is less than the minimum required, 0.1"); testMinResource(null, 2048L, true, "Per instance CPU requested, 0.0, for function is less than the minimum required, 0.1"); testMinResource(null, 512L, true, "Per instance CPU requested, 0.0, for function is less than the minimum required, 0.1"); }
void validateMinResourcesRequired(Function.FunctionDetails functionDetails) { if (functionInstanceMinResources != null) { Double minCpu = functionInstanceMinResources.getCpu(); Long minRam = functionInstanceMinResources.getRam(); if (minCpu != null) { if (functionDetails.getResources() == null) { throw new IllegalArgumentException( String.format("Per instance CPU requested is not specified. Must specify CPU requested for function to be at least %s", minCpu)); } else if (functionDetails.getResources().getCpu() < minCpu) { throw new IllegalArgumentException( String.format("Per instance CPU requested, %s, for function is less than the minimum required, %s", functionDetails.getResources().getCpu(), minCpu)); } } if (minRam != null) { if (functionDetails.getResources() == null) { throw new IllegalArgumentException( String.format("Per instance RAM requested is not specified. Must specify RAM requested for function to be at least %s", minRam)); } else if (functionDetails.getResources().getRam() < minRam) { throw new IllegalArgumentException( String.format("Per instance RAM requested, %s, for function is less than the minimum required, %s", functionDetails.getResources().getRam(), minRam)); } } } }
KubernetesRuntimeFactory implements RuntimeFactory { void validateMinResourcesRequired(Function.FunctionDetails functionDetails) { if (functionInstanceMinResources != null) { Double minCpu = functionInstanceMinResources.getCpu(); Long minRam = functionInstanceMinResources.getRam(); if (minCpu != null) { if (functionDetails.getResources() == null) { throw new IllegalArgumentException( String.format("Per instance CPU requested is not specified. Must specify CPU requested for function to be at least %s", minCpu)); } else if (functionDetails.getResources().getCpu() < minCpu) { throw new IllegalArgumentException( String.format("Per instance CPU requested, %s, for function is less than the minimum required, %s", functionDetails.getResources().getCpu(), minCpu)); } } if (minRam != null) { if (functionDetails.getResources() == null) { throw new IllegalArgumentException( String.format("Per instance RAM requested is not specified. Must specify RAM requested for function to be at least %s", minRam)); } else if (functionDetails.getResources().getRam() < minRam) { throw new IllegalArgumentException( String.format("Per instance RAM requested, %s, for function is less than the minimum required, %s", functionDetails.getResources().getRam(), minRam)); } } } } }
KubernetesRuntimeFactory implements RuntimeFactory { void validateMinResourcesRequired(Function.FunctionDetails functionDetails) { if (functionInstanceMinResources != null) { Double minCpu = functionInstanceMinResources.getCpu(); Long minRam = functionInstanceMinResources.getRam(); if (minCpu != null) { if (functionDetails.getResources() == null) { throw new IllegalArgumentException( String.format("Per instance CPU requested is not specified. Must specify CPU requested for function to be at least %s", minCpu)); } else if (functionDetails.getResources().getCpu() < minCpu) { throw new IllegalArgumentException( String.format("Per instance CPU requested, %s, for function is less than the minimum required, %s", functionDetails.getResources().getCpu(), minCpu)); } } if (minRam != null) { if (functionDetails.getResources() == null) { throw new IllegalArgumentException( String.format("Per instance RAM requested is not specified. Must specify RAM requested for function to be at least %s", minRam)); } else if (functionDetails.getResources().getRam() < minRam) { throw new IllegalArgumentException( String.format("Per instance RAM requested, %s, for function is less than the minimum required, %s", functionDetails.getResources().getRam(), minRam)); } } } }  }
KubernetesRuntimeFactory implements RuntimeFactory { void validateMinResourcesRequired(Function.FunctionDetails functionDetails) { if (functionInstanceMinResources != null) { Double minCpu = functionInstanceMinResources.getCpu(); Long minRam = functionInstanceMinResources.getRam(); if (minCpu != null) { if (functionDetails.getResources() == null) { throw new IllegalArgumentException( String.format("Per instance CPU requested is not specified. Must specify CPU requested for function to be at least %s", minCpu)); } else if (functionDetails.getResources().getCpu() < minCpu) { throw new IllegalArgumentException( String.format("Per instance CPU requested, %s, for function is less than the minimum required, %s", functionDetails.getResources().getCpu(), minCpu)); } } if (minRam != null) { if (functionDetails.getResources() == null) { throw new IllegalArgumentException( String.format("Per instance RAM requested is not specified. Must specify RAM requested for function to be at least %s", minRam)); } else if (functionDetails.getResources().getRam() < minRam) { throw new IllegalArgumentException( String.format("Per instance RAM requested, %s, for function is less than the minimum required, %s", functionDetails.getResources().getRam(), minRam)); } } } }  @Override boolean externallyManaged(); @Override void initialize(WorkerConfig workerConfig, AuthenticationConfig authenticationConfig,
                           SecretsProviderConfigurator secretsProviderConfigurator,
                           Optional<FunctionAuthProvider> functionAuthProvider,
                           Optional<RuntimeCustomizer> runtimeCustomizer); @Override KubernetesRuntime createContainer(InstanceConfig instanceConfig, String codePkgUrl,
                                             String originalCodeFileName,
                                             Long expectedHealthCheckInterval); @Override void close(); @Override void doAdmissionChecks(Function.FunctionDetails functionDetails); @VisibleForTesting void setupClient(); @Override Optional<KubernetesFunctionAuthProvider> getAuthProvider(); @Override Optional<KubernetesManifestCustomizer> getRuntimeCustomizer(); }
KubernetesRuntimeFactory implements RuntimeFactory { void validateMinResourcesRequired(Function.FunctionDetails functionDetails) { if (functionInstanceMinResources != null) { Double minCpu = functionInstanceMinResources.getCpu(); Long minRam = functionInstanceMinResources.getRam(); if (minCpu != null) { if (functionDetails.getResources() == null) { throw new IllegalArgumentException( String.format("Per instance CPU requested is not specified. Must specify CPU requested for function to be at least %s", minCpu)); } else if (functionDetails.getResources().getCpu() < minCpu) { throw new IllegalArgumentException( String.format("Per instance CPU requested, %s, for function is less than the minimum required, %s", functionDetails.getResources().getCpu(), minCpu)); } } if (minRam != null) { if (functionDetails.getResources() == null) { throw new IllegalArgumentException( String.format("Per instance RAM requested is not specified. Must specify RAM requested for function to be at least %s", minRam)); } else if (functionDetails.getResources().getRam() < minRam) { throw new IllegalArgumentException( String.format("Per instance RAM requested, %s, for function is less than the minimum required, %s", functionDetails.getResources().getRam(), minRam)); } } } }  @Override boolean externallyManaged(); @Override void initialize(WorkerConfig workerConfig, AuthenticationConfig authenticationConfig,
                           SecretsProviderConfigurator secretsProviderConfigurator,
                           Optional<FunctionAuthProvider> functionAuthProvider,
                           Optional<RuntimeCustomizer> runtimeCustomizer); @Override KubernetesRuntime createContainer(InstanceConfig instanceConfig, String codePkgUrl,
                                             String originalCodeFileName,
                                             Long expectedHealthCheckInterval); @Override void close(); @Override void doAdmissionChecks(Function.FunctionDetails functionDetails); @VisibleForTesting void setupClient(); @Override Optional<KubernetesFunctionAuthProvider> getAuthProvider(); @Override Optional<KubernetesManifestCustomizer> getRuntimeCustomizer();  }