diff --git a/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/components/OrchestrationServiceClient.java b/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/components/OrchestrationServiceClient.java new file mode 100644 index 0000000000000000000000000000000000000000..fb140b3e12cc2ab5de35b76ecf140e14f3de49b9 --- /dev/null +++ b/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/components/OrchestrationServiceClient.java @@ -0,0 +1,15 @@ +package com.informationcatalyst.enact.application_controller.containerEnabler.components; + +import org.springframework.stereotype.Component; + +@Component +public class OrchestrationServiceClient { + public void blockScaling(String containerId) { + // Actual implementation would integrate with Kubernetes/Docker API + System.out.println("Blocking scaling for container: " + containerId); + // Implementation might include: + // 1. Annotating Kubernetes deployment + // 2. Modifying auto-scaling groups + // 3. Triggering alerts + } +} diff --git a/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/controllers/ContainerLicenseManagerController.java b/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/controllers/ContainerLicenseManagerController.java new file mode 100644 index 0000000000000000000000000000000000000000..3ff555304048bc24f2e7632acd32d4fcbc3e2d62 --- /dev/null +++ b/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/controllers/ContainerLicenseManagerController.java @@ -0,0 +1,31 @@ +package com.informationcatalyst.enact.application_controller.containerEnabler.controllers; + +import com.informationcatalyst.enact.application_controller.containerEnabler.models.LicenseCompliance; +import com.informationcatalyst.enact.application_controller.containerEnabler.models.LicenseViolation; + +import com.informationcatalyst.enact.application_controller.containerEnabler.services.ContainerLicenseManageService; + +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/licenses") +public class ContainerLicenseManagerController { + private ContainerLicenseManageService licenseManager; + + @GetMapping("/check/{containerId}") + public LicenseCompliance checkLicense(@PathVariable String containerId) { + return licenseManager.checkLicense(containerId); + } + + @PostMapping("/block-scaling/{containerId}") + public boolean blockUnlicensedScaling(@PathVariable String containerId) { + return licenseManager.blockUnlicensedScaling(containerId); + } + + @GetMapping("/audit") + public List<LicenseViolation> auditClusterLicenses() { + return licenseManager.auditClusterLicenses(); + } +} diff --git a/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/interfaces/LicenseRepository.java b/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/interfaces/LicenseRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..cebaa7fec9b180882b15b463efeffc04d5f8fa04 --- /dev/null +++ b/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/interfaces/LicenseRepository.java @@ -0,0 +1,11 @@ +package com.informationcatalyst.enact.application_controller.containerEnabler.interfaces; + +import com.informationcatalyst.enact.application_controller.containerEnabler.models.LicenseCompliance; + +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface LicenseRepository extends JpaRepository<LicenseCompliance, Long> { + Optional<LicenseCompliance> findByContainerId(String containerId); +} diff --git a/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/models/LicenseCompliance.java b/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/models/LicenseCompliance.java new file mode 100644 index 0000000000000000000000000000000000000000..160d62f91ada65fdedad1ef6cc6eab7b2ceba08b --- /dev/null +++ b/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/models/LicenseCompliance.java @@ -0,0 +1,79 @@ +package com.informationcatalyst.enact.application_controller.containerEnabler.models; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Entity +@Data +@AllArgsConstructor +public class LicenseCompliance { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String containerId; + private boolean isCompliant; + private String licenseKey; + private String message; + + // Default constructor (required by JPA) + public LicenseCompliance() { + } + + // All-args constructor (excluding ID which is auto-generated) + public LicenseCompliance(String containerId, boolean isCompliant, String message) { + this.containerId = containerId; + this.isCompliant = isCompliant; + this.message = message; + } + + // Full constructor (optional, includes licenseKey) + public LicenseCompliance(String containerId, boolean isCompliant, String licenseKey, String message) { + this.containerId = containerId; + this.isCompliant = isCompliant; + this.licenseKey = licenseKey; + this.message = message; + } + + // Getters and setters + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getContainerId() { + return containerId; + } + + public void setContainerId(String containerId) { + this.containerId = containerId; + } + + public boolean isCompliant() { + return isCompliant; + } + + public void setCompliant(boolean compliant) { + isCompliant = compliant; + } + + public String getLicenseKey() { + return licenseKey; + } + + public void setLicenseKey(String licenseKey) { + this.licenseKey = licenseKey; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/models/LicenseViolation.java b/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/models/LicenseViolation.java new file mode 100644 index 0000000000000000000000000000000000000000..7f2947e076d494663e072d5728d8346a6afffcf4 --- /dev/null +++ b/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/models/LicenseViolation.java @@ -0,0 +1,37 @@ +package com.informationcatalyst.enact.application_controller.containerEnabler.models; + +import lombok.Data; + +@Data +public class LicenseViolation { + private String containerId; + private String violationReason; + + // Default constructor + public LicenseViolation() { + } + + // All-arguments constructor + public LicenseViolation(String containerId, String violationReason) { + this.containerId = containerId; + this.violationReason = violationReason; + } + + // Getters + public String getContainerId() { + return containerId; + } + + public String getViolationReason() { + return violationReason; + } + + // Setters + public void setContainerId(String containerId) { + this.containerId = containerId; + } + + public void setViolationReason(String violationReason) { + this.violationReason = violationReason; + } +} \ No newline at end of file diff --git a/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/services/ContainerLicenseManageService.java b/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/services/ContainerLicenseManageService.java new file mode 100644 index 0000000000000000000000000000000000000000..eb4be0b29e08787b0855df678694cc1bfafe574b --- /dev/null +++ b/src/main/java/com/informationcatalyst/enact/application_controller/containerEnabler/services/ContainerLicenseManageService.java @@ -0,0 +1,74 @@ +package com.informationcatalyst.enact.application_controller.containerEnabler.services; + +import com.informationcatalyst.enact.application_controller.containerEnabler.models.LicenseCompliance; +import com.informationcatalyst.enact.application_controller.containerEnabler.models.LicenseViolation; + +import com.informationcatalyst.enact.application_controller.containerEnabler.interfaces.LicenseRepository; +import com.informationcatalyst.enact.application_controller.containerEnabler.components.OrchestrationServiceClient; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class ContainerLicenseManageService { + private LicenseRepository licenseRepository; + private OrchestrationServiceClient orchestrationClient; + + public ContainerLicenseManageService(LicenseRepository licenseRepository, + OrchestrationServiceClient orchestrationClient) { + this.licenseRepository = licenseRepository; + this.orchestrationClient = orchestrationClient; + } + + @Transactional + public LicenseCompliance checkLicense(String containerId) { + return licenseRepository.findByContainerId(containerId) + .orElseGet(() -> { + // License not found - new container + boolean isValid = validateNewContainer(containerId); + String message = isValid ? "Valid license" : "Missing license for container"; + + LicenseCompliance compliance = new LicenseCompliance( + containerId, + isValid, + message); + return licenseRepository.save(compliance); + }); + } + + @Transactional + public boolean blockUnlicensedScaling(String containerId) { + LicenseCompliance compliance = checkLicense(containerId); + + if (!compliance.isCompliant()) { + orchestrationClient.blockScaling(containerId); + return true; // Blocking action performed + } + return false; // No blocking needed + } + + public List<LicenseViolation> auditClusterLicenses() { + List<LicenseViolation> violations = new ArrayList<>(); + + licenseRepository.findAll().forEach(compliance -> { + if (!compliance.isCompliant()) { + violations.add(new LicenseViolation( + compliance.getContainerId(), + "Unlicensed container operation")); + } + }); + + return violations; + } + + private boolean validateNewContainer(String containerId) { + // Implement actual license validation logic: + // 1. Check with external license server + // 2. Validate license key format + // 3. Check license pool capacity + return containerId.endsWith("-licensed"); // Mock logic + } +}