Skip to content
Snippets Groups Projects
Commit fb28b432 authored by fareed.hussain's avatar fareed.hussain
Browse files

282-c02.1.232-create-function-Adaptation-Component-Container-Enabler-Container...

282-c02.1.232-create-function-Adaptation-Component-Container-Enabler-Container-License-Manager-11072025
parent 7f6cceed
No related merge requests found
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
}
}
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();
}
}
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);
}
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;
}
}
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
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
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment