Skip to content

Commit

Permalink
MIGENG-138 WIR Complexity rules and tests - WIP (#17)
Browse files Browse the repository at this point in the history
* MIGENG-138 WIR Complexity rules and tests - WIP

* MIGENG-138 WIR Complexity rules and tests - WIP

* MIGENG-138: complete Complexity rules

* MIGENG-138: complete Complexity rules

* MIGENG-138 Fixed Agenda Groups focusing order (#3)

* MIGENG-138: Integration test with added Complexity rules scenarios

* Update src/main/java/org/jboss/xavier/analytics/pojo/output/workload/inventory/WorkloadInventoryReportModel.java

Co-Authored-By: Marco Rizzi <[email protected]>

* Update src/main/java/org/jboss/xavier/analytics/pojo/output/workload/inventory/WorkloadInventoryReportModel.java

Co-Authored-By: Marco Rizzi <[email protected]>

* Update src/main/java/org/jboss/xavier/analytics/pojo/output/workload/inventory/WorkloadInventoryReportModel.java

Co-Authored-By: Marco Rizzi <[email protected]>

* Update src/main/java/org/jboss/xavier/analytics/pojo/output/workload/inventory/WorkloadInventoryReportModel.java

Co-Authored-By: Marco Rizzi <[email protected]>

* Update src/main/java/org/jboss/xavier/analytics/functions/HelperFunctions.java

Co-Authored-By: Marco Rizzi <[email protected]>

* Update src/main/java/org/jboss/xavier/analytics/functions/HelperFunctions.java

Co-Authored-By: Marco Rizzi <[email protected]>

* Update src/main/java/org/jboss/xavier/analytics/functions/HelperFunctions.java

Co-Authored-By: Marco Rizzi <[email protected]>

* Update src/main/java/org/jboss/xavier/analytics/functions/HelperFunctions.java

Co-Authored-By: Marco Rizzi <[email protected]>

* Update src/main/resources/org/jboss/xavier/analytics/rules/workload/inventory/Complexity.drl

Co-Authored-By: Marco Rizzi <[email protected]>

* Update src/main/resources/org/jboss/xavier/analytics/rules/workload/inventory/Complexity.drl

Co-Authored-By: Marco Rizzi <[email protected]>

* MIGENG-138: Complexity rule & test changes as per review

* MIGENG-138: Complexity rule & test changes as per review
  • Loading branch information
m-brophy authored and mrizzi committed Aug 9, 2019
1 parent e71fabf commit b4ff013
Show file tree
Hide file tree
Showing 8 changed files with 1,003 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,55 @@
package org.jboss.xavier.analytics.functions;

import java.util.Arrays;

public class HelperFunctions
{
public static int round(double value)
{
return (int) Math.round(value);
}

public static boolean isSupportedOS(String osToCheck)
{
return Arrays.stream(OSSupport.values()).anyMatch(value -> osToCheck.toLowerCase().contains(value.getName().toLowerCase()) && value.isSupported());
}

public static boolean isUnsupportedOS(String osToCheck)
{
return Arrays.stream(OSSupport.values()).anyMatch(value -> osToCheck.toLowerCase().contains(value.getName().toLowerCase()) && !value.isSupported());
}

public static boolean isUndetectedOS(String osToCheck)
{
return Arrays.stream(OSSupport.values()).noneMatch(value -> osToCheck.toLowerCase().contains(value.getName().toLowerCase()));
}

public enum OSSupport{
RHEL("Red Hat Enterprise Linux", true),
SUSE("SUSE Linux Enterprise Server", true),
WINDOWS("Windows",true),
ORACLE("Oracle Enterprise Linux",false),
CENTOS("CentOS",false),
DEBIAN("Debian",false),
UBUNTU("Ubuntu",false);

private final String name;
private final boolean isSupported;

OSSupport(String name, boolean isSupported)
{
this.name = name;
this.isSupported = isSupported;
}

boolean isSupported()
{
return this.isSupported;
}

public String getName()
{
return this.name;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -22,6 +23,11 @@ public class WorkloadInventoryReportModel
public static final String RDM_DISK_FLAG_NAME = "RDM";
public static final String SHARED_DISK_FLAG_NAME = "Shared Disk";

public static final String COMPLEXITY_EASY = "Easy";
public static final String COMPLEXITY_MEDIUM = "Medium";
public static final String COMPLEXITY_HARD = "Hard";
public static final String COMPLEXITY_UNKNOWN = "Unknown";

@Id
@GeneratedValue(strategy = javax.persistence.GenerationType.AUTO, generator = "WORKLOADINVENTORYREPORTMODEL_ID_GENERATOR")
private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ rule "Copy basic fields and agenda controller"
workloadInventoryReport.setOsName(vmWorkloadInventoryModel.getOsProductName());

insert(workloadInventoryReport);
kcontext.getKieRuntime().getAgenda().getAgendaGroup("Flags").setFocus();
kcontext.getKieRuntime().getAgenda().getAgendaGroup("Targets").setFocus();
kcontext.getKieRuntime().getAgenda().getAgendaGroup("Complexity").setFocus();
kcontext.getKieRuntime().getAgenda().getAgendaGroup("Workloads").setFocus();
kcontext.getKieRuntime().getAgenda().getAgendaGroup("Complexity").setFocus();
kcontext.getKieRuntime().getAgenda().getAgendaGroup("Targets").setFocus();
kcontext.getKieRuntime().getAgenda().getAgendaGroup("Flags").setFocus();
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package org.jboss.xavier.analytics.rules.workload.inventory;

import org.jboss.xavier.analytics.pojo.input.workload.inventory.VMWorkloadInventoryModel
import org.jboss.xavier.analytics.pojo.output.workload.inventory.WorkloadInventoryReportModel
import java.util.HashSet;

import function org.jboss.xavier.analytics.functions.HelperFunctions.isSupportedOS;
import function org.jboss.xavier.analytics.functions.HelperFunctions.isUnsupportedOS;
import function org.jboss.xavier.analytics.functions.HelperFunctions.isUndetectedOS;

dialect "java"
agenda-group "Complexity"
lock-on-active true
auto-focus false

rule "No_Flag_Supported_OS"
when
workloadInventoryReport : WorkloadInventoryReportModel(
flagsIMS == null,
osDescription != null,
isSupportedOS(osDescription)
)
then
modify(workloadInventoryReport)
{
setComplexity(WorkloadInventoryReportModel.COMPLEXITY_EASY)
}
end

rule "One_Flag_Supported_OS"
when
workloadInventoryReport : WorkloadInventoryReportModel(
flagsIMS != null,
flagsIMS.size() == 1,
osDescription != null,
isSupportedOS(osDescription)
)
then
modify(workloadInventoryReport)
{
setComplexity(WorkloadInventoryReportModel.COMPLEXITY_MEDIUM)
}
end

rule "More_Than_One_Flag_Supported_OS"
when
workloadInventoryReport : WorkloadInventoryReportModel(
flagsIMS != null,
flagsIMS.size() > 1,
osDescription != null,
isSupportedOS(osDescription)
)
then
modify(workloadInventoryReport)
{
setComplexity(WorkloadInventoryReportModel.COMPLEXITY_HARD)
}
end

rule "No_Flags_Not_Supported_OS"
when
workloadInventoryReport : WorkloadInventoryReportModel(
flagsIMS == null,
osDescription != null,
isUnsupportedOS(osDescription)
)
then
modify(workloadInventoryReport)
{
setComplexity(WorkloadInventoryReportModel.COMPLEXITY_MEDIUM)
}
end

rule "One_Or_More_Flags_Not_Supported_OS"
when
workloadInventoryReport : WorkloadInventoryReportModel(
flagsIMS != null,
flagsIMS.size() >= 1,
osDescription != null,
isUnsupportedOS(osDescription)
)
then
modify(workloadInventoryReport)
{
setComplexity(WorkloadInventoryReportModel.COMPLEXITY_HARD)
}
end

rule "Not_Detected_OS"
when
workloadInventoryReport : WorkloadInventoryReportModel(
osDescription != null,
isUndetectedOS(osDescription)
)
then
modify(workloadInventoryReport)
{
setComplexity(WorkloadInventoryReportModel.COMPLEXITY_UNKNOWN)
}
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.util.HashSet;
dialect "java"
agenda-group "Flags"
lock-on-active true
auto-focus false

rule "Flag_Nics"
when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import java.util.HashSet;
dialect "java"
agenda-group "Workloads"
lock-on-active true
auto-focus false

rule "Workloads_sample_systemServicesNames_rule"
when
vmWorkloadInventoryModel : VMWorkloadInventoryModel(
systemServicesNames != null,
systemServicesNames.size() > 0
)
//workloadInventoryReport : WorkloadInventoryReportModel()
workloadInventoryReport : WorkloadInventoryReportModel()
then
System.out.println(vmWorkloadInventoryModel.getVmName() + " has systemServicesNames: ");
vmWorkloadInventoryModel.getSystemServicesNames().forEach(System.out::println);
Expand All @@ -26,7 +27,7 @@ rule "Workloads_sample_files_rule"
files != null,
files.size() > 0
)
//workloadInventoryReport : WorkloadInventoryReportModel()
workloadInventoryReport : WorkloadInventoryReportModel()
then
System.out.println(vmWorkloadInventoryModel.getVmName() + " has files: ");
vmWorkloadInventoryModel.getFiles().forEach((key, value) -> System.out.println(key));
Expand Down
Loading

0 comments on commit b4ff013

Please sign in to comment.