Skip to content

Commit

Permalink
[Subscriptions Release] - pre tag commit: 'rhsm-subscriptions-1.0.84'.
Browse files Browse the repository at this point in the history
  • Loading branch information
kahowell committed Feb 11, 2022
2 parents 9c7abf8 + 0e15c08 commit 82df71e
Show file tree
Hide file tree
Showing 18 changed files with 196 additions and 68 deletions.
100 changes: 58 additions & 42 deletions bin/insert-mock-hosts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ def generate_host(inventory_id=None, insights_id=None, account_number=None, org_
subscription_manager_id=None, cores=None, sockets=None, is_guest=None, hypervisor_uuid=None,
hardware_type=None, measurement_type=None, num_of_guests=None, last_seen=None, product=None,
sla=None, usage=None, is_unmapped_guest=None, is_hypervisor=None, cloud_provider=None,
skip_buckets=False, is_hbi=False):

skip_buckets=False, is_hbi=False, is_marketplace=False):
account = account_number or "account123"
host_id = uuid.uuid4()
inventory_id=inventory_id or uuid.uuid4()
insights_id=insights_id or uuid.uuid4()
inventory_id = inventory_id or uuid.uuid4()
insights_id = insights_id or uuid.uuid4()

if not is_guest:
hypervisor_uuid = None
Expand Down Expand Up @@ -47,6 +46,7 @@ def generate_host(inventory_id=None, insights_id=None, account_number=None, org_
'cores_per_socket': cores // sockets,
'number_of_sockets': sockets,
'cloud_provider': cloud_provider,
'is_marketplace': is_marketplace,
}),
'stale_timestamp': '2030-01-01',
'reporter': 'rhsm-conduit',
Expand Down Expand Up @@ -98,29 +98,32 @@ def _generate_insert(table, **host_fields):
values = ','.join(db_repr(value) for value in values)
output.write(f'insert into {table}({fields}) values ({values});\n')

def _generate_buckets(host_id, product, sla, usage, as_hypervisor=False, measurement_type=None, cores=None, sockets=None):
sla = sla or 'Premium'
usage = usage or 'Production'
bucket_fields = {
'host_id': host_id,
'product_id': product or 'RHEL',
'as_hypervisor': as_hypervisor,
'measurement_type': measurement_type,
'cores': cores,
'sockets': sockets,
}

sla_vals = ["_ANY", sla]
usage_vals = ["_ANY", usage]
for next_sla in sla_vals:
for next_usage in usage_vals:
_generate_insert("host_tally_buckets", sla=next_sla, usage=next_usage, **bucket_fields)
def _generate_buckets(host_id, product, sla, usage, as_hypervisor=False, measurement_type=None, cores=None,
sockets=None):
sla = sla or 'Premium'
usage = usage or 'Production'
bucket_fields = {
'host_id': host_id,
'product_id': product or 'RHEL',
'as_hypervisor': as_hypervisor,
'measurement_type': measurement_type,
'cores': cores,
'sockets': sockets,
}

sla_vals = ["_ANY", sla]
usage_vals = ["_ANY", usage]
for next_sla in sla_vals:
for next_usage in usage_vals:
_generate_insert("host_tally_buckets", sla=next_sla, usage=next_usage, **bucket_fields)


def _create_account_service(account, service_type):
fields = ','.join(['account_number', 'service_type'])
values = ','.join(db_repr(value) for value in [account, service_type])
output.write(f'insert into account_services ({fields}) values ({values}) ON CONFLICT ON CONSTRAINT account_services_pkey DO NOTHING;\n')
fields = ','.join(['account_number', 'service_type'])
values = ','.join(db_repr(value) for value in [account, service_type])
output.write(
f'insert into account_services ({fields}) values ({values}) ON CONFLICT ON CONSTRAINT account_services_pkey DO NOTHING;\n')


parser = argparse.ArgumentParser(description='Insert mock hosts into the a local DB')
Expand Down Expand Up @@ -178,6 +181,8 @@ parser.add_argument('--opt-in', action='store_true',
help='Opt in this account')
parser.add_argument('--clear', action='store_true',
help='Clear data in the hosts table and related tables')
parser.add_argument('--marketplace', action='store_true', dest='is_marketplace',
help='Set a system as a Marketplace instance')

args = parser.parse_args()
if args.is_hbi:
Expand All @@ -191,7 +196,7 @@ os.environ['PGPASSWORD'] = args.db_password or default_password

psql = None
if not args.output_sql:
psql = subprocess.Popen('psql', stdin=subprocess.PIPE, shell=True, text=True)
psql = subprocess.Popen('psql', stdin=subprocess.PIPE, shell=True, encoding='utf-8')
output = psql.stdin

output.write('begin;')
Expand All @@ -207,39 +212,49 @@ for i in range(args.num_accounts):
account = args.account
if args.opt_in:
_generate_insert('account_config',
account_number=account,
sync_enabled=True,
reporting_enabled=True,
opt_in_type='API',
created='2021-01-01',
updated='2021-01-01'
)
account_number=account,
sync_enabled=True,
reporting_enabled=True,
opt_in_type='API',
created='2021-01-01',
updated='2021-01-01'
)

product = args.product or "RHEL"

for i in range(args.num_aws):
generate_host(account_number=account, hardware_type='VIRTUAL', measurement_type='CLOUD',
product=args.product, sla=args.sla, usage=args.usage, cores=args.cores, sockets=args.sockets, is_hbi=args.is_hbi,
cloud_provider='AWS')
product=args.product, sla=args.sla, usage=args.usage, cores=args.cores, sockets=args.sockets,
is_hbi=args.is_hbi,
cloud_provider='AWS', is_marketplace=args.is_marketplace)

for i in range(args.num_physical):
generate_host(account_number=account, hardware_type='PHYSICAL', measurement_type='PHYSICAL',
product=args.product, sla=args.sla, usage=args.usage, cores=args.cores, sockets=args.sockets, is_hbi=args.is_hbi)
product=args.product, sla=args.sla, usage=args.usage, cores=args.cores, sockets=args.sockets,
is_hbi=args.is_hbi,
is_marketplace=args.is_marketplace)

hypervisor = None
for i in range(args.num_hypervisors):
hypervisor = generate_host(account_number=account, hardware_type='PHYSICAL', measurement_type='VIRTUAL', product=args.product,
sla=args.sla, usage=args.usage, cores=args.cores, sockets=args.sockets, is_hypervisor=True, is_hbi=args.is_hbi)
hypervisor = generate_host(account_number=account, hardware_type='PHYSICAL', measurement_type='VIRTUAL',
product=args.product,
sla=args.sla, usage=args.usage, cores=args.cores, sockets=args.sockets,
is_hypervisor=True, is_hbi=args.is_hbi,
is_marketplace=args.is_marketplace)
# create a physical entry for the host as well.
generate_host(account_number=account, hardware_type='PHYSICAL', measurement_type='PHYSICAL', product=args.product,
sla=args.sla, usage=args.usage, cores=args.cores, sockets=args.sockets, is_hypervisor=True, is_hbi=args.is_hbi)
generate_host(account_number=account, hardware_type='PHYSICAL', measurement_type='PHYSICAL',
product=args.product,
sla=args.sla, usage=args.usage, cores=args.cores, sockets=args.sockets, is_hypervisor=True,
is_hbi=args.is_hbi,
is_marketplace=args.is_marketplace)

create_unmapped = args.unmapped_guests
for i in range(args.num_guests):
if args.hypervisor_id:
hypervisor_uuid = args.hypervisor_id
elif hypervisor is not None:
hypervisor_uuid = hypervisor.get('subscription_manager_id') or json.loads(hypervisor['canonical_facts'])['subscription_manager_id']
hypervisor_uuid = hypervisor.get('subscription_manager_id') or json.loads(hypervisor['canonical_facts'])[
'subscription_manager_id']
# If we are associating the guests with a created hypervisor host, don't allow it to be unmapped
# since it was considered as reported.
create_unmapped = False
Expand All @@ -248,9 +263,10 @@ for i in range(args.num_accounts):

skip_buckets = "RHEL" in product.upper()
generate_host(account_number=account, hardware_type='VIRTUALIZED', is_guest=True,
product=args.product, sla=args.sla, usage=args.usage, hypervisor_uuid=hypervisor_uuid,
cores=args.cores, sockets=args.sockets, is_unmapped_guest=create_unmapped,
skip_buckets=skip_buckets, is_hbi=args.is_hbi)
product=args.product, sla=args.sla, usage=args.usage, hypervisor_uuid=hypervisor_uuid,
cores=args.cores, sockets=args.sockets, is_unmapped_guest=create_unmapped,
skip_buckets=skip_buckets, is_hbi=args.is_hbi,
is_marketplace=args.is_marketplace)

output.write('commit;')

Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {

plugins {
id "io.spring.dependency-management" version "1.0.11.RELEASE"
id "com.diffplug.spotless" version "6.2.1"
id "com.diffplug.spotless" version "6.2.2"
id "jacoco"
id "org.sonarqube" version "3.3"
id "org.springframework.boot" version "2.6.3"
Expand All @@ -27,16 +27,16 @@ plugins {


ext {
swagger_annotations_version = "1.6.4"
swagger_ui_version = "4.4.1"
swagger_annotations_version = "1.6.5"
swagger_ui_version = "4.5.0"
resteasy_version = "3.6.3.Final"
spring_boot_version = "2.6.3"
jboss_jaxrs_api_version = "2.0.2.Final"
resteasy_spring_boot_starter_version = "3.9.1.Final"
kafka_avro_serializer_version = "7.0.1"
avro_version = "1.11.0"
webjars_locator_version = "0.42"
hawtio_springboot_version = "2.14.4"
hawtio_springboot_version = "2.14.5"
guava_version = "31.0.1-jre"
janino_version = "3.1.6"
splunk_library_javalogging_version = "1.11.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public OrgInventory getConsumersForOrg(
consumer1.getFacts().put("virt.is_guest", "True");
consumer1.getFacts().put("ocm.units", "Sockets");
consumer1.getFacts().put("ocm.billing_model", "standard");
consumer1.getFacts().put("distribution.name", "Red Hat Enterprise Linux Workstation");
consumer1.getFacts().put("distribution.version", "6.3");
InstalledProducts product = new InstalledProducts();
product.setProductId("72");
consumer1.getInstalledProducts().add(product);
Expand Down
24 changes: 15 additions & 9 deletions deploy/rhsm-clowdapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ kind: Template
metadata:
name: rhsm
parameters:
- name: HAWTIO_BASE_PATH
value: /hawtio
- name: SUBSCRIPTIONS_HAWTIO_BASE_PATH
value: /app/rhsm-subscriptions/hawtio
- name: MARKETPLACE_HAWTIO_BASE_PATH
value: /app/rhsm-marketplace/hawtio
- name: METRICS_WORKER_HAWTIO_BASE_PATH
value: /app/rhsm-metrics/hawtio
- name: CONDUIT_HAWTIO_BASE_PATH
value: /app/rhsm-conduit/hawtio
- name: CAPACITY_INGRESS_HAWTIO_BASE_PATH
value: /app/rhsm-capacity-ingress/hawtio
- name: SERVER_MAX_HTTP_HEADER_SIZE
value: '48000'
- name: LOGGING_LEVEL_ROOT
Expand Down Expand Up @@ -285,8 +293,6 @@ objects:
value: 'true'
- name: SERVER_MAX_HTTP_HEADER_SIZE
value: ${SERVER_MAX_HTTP_HEADER_SIZE}
- name: HAWTIO_BASE_PATH
value: ${HAWTIO_BASE_PATH}
- name: LOG_FILE
value: /logs/server.log
- name: JAVA_MAX_MEM_RATIO
Expand Down Expand Up @@ -488,7 +494,7 @@ objects:
- name: SERVER_MAX_HTTP_HEADER_SIZE
value: ${SERVER_MAX_HTTP_HEADER_SIZE}
- name: HAWTIO_BASE_PATH
value: ${HAWTIO_BASE_PATH}
value: ${SUBSCRIPTIONS_HAWTIO_BASE_PATH}
- name: LOG_FILE
value: /logs/server.log
- name: JAVA_MAX_MEM_RATIO
Expand Down Expand Up @@ -694,7 +700,7 @@ objects:
- name: SERVER_MAX_HTTP_HEADER_SIZE
value: ${SERVER_MAX_HTTP_HEADER_SIZE}
- name: HAWTIO_BASE_PATH
value: ${HAWTIO_BASE_PATH}
value: ${MARKETPLACE_HAWTIO_BASE_PATH}
- name: LOG_FILE
value: /logs/server.log
- name: JAVA_MAX_MEM_RATIO
Expand Down Expand Up @@ -908,7 +914,7 @@ objects:
- name: SERVER_MAX_HTTP_HEADER_SIZE
value: ${SERVER_MAX_HTTP_HEADER_SIZE}
- name: HAWTIO_BASE_PATH
value: ${HAWTIO_BASE_PATH}
value: ${METRICS_WORKER_HAWTIO_BASE_PATH}
- name: LOG_FILE
value: /logs/server.log
- name: JAVA_MAX_MEM_RATIO
Expand Down Expand Up @@ -1111,7 +1117,7 @@ objects:
- name: AB_JOLOKIA_OFF
value: 'true'
- name: HAWTIO_BASE_PATH
value: ${HAWTIO_BASE_PATH}
value: ${CONDUIT_HAWTIO_BASE_PATH}
- name: LOG_FILE
value: /logs/server.log
- name: JAVA_MAX_MEM_RATIO
Expand Down Expand Up @@ -1284,7 +1290,7 @@ objects:
- name: AB_JOLOKIA_OFF
value: 'true'
- name: HAWTIO_BASE_PATH
value: ${HAWTIO_BASE_PATH}
value: ${CAPACITY_INGRESS_HAWTIO_BASE_PATH}
- name: LOG_FILE
value: /logs/server.log
- name: JAVA_MAX_MEM_RATIO
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = 1.0.83
version = 1.0.84
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand Down Expand Up @@ -73,6 +74,7 @@ public class ApiSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Autowired protected ObjectMapper mapper;
@Autowired protected SecurityProperties secProps;
@Autowired protected ManagementServerProperties actuatorProps;
@Autowired protected RbacProperties rbacProperties;
@Autowired protected ConfigurableEnvironment env;
@Autowired protected RbacService rbacService;
Expand Down Expand Up @@ -164,6 +166,12 @@ protected void configure(HttpSecurity http) throws Exception {
// ingress security uses server settings (require ssl cert auth), so permit all here
.antMatchers(String.format("/%s/ingress/**", apiPath))
.permitAll()
// Allow access to the Spring Actuator "root" which displays the available endpoints
.requestMatchers(
request ->
request.getServerPort() == actuatorProps.getPort()
&& request.getContextPath().equals(actuatorProps.getBasePath()))
.permitAll()
.requestMatchers(EndpointRequest.to("health", "info", "prometheus", "hawtio"))
.permitAll()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@ public Optional<HostTallyBucket> collect(
HardwareMeasurementType appliedType = null;
// Cloud provider hosts only account for a single socket.
if (normalizedFacts.getCloudProviderType() != null) {
appliedSockets = 1;
appliedSockets = normalizedFacts.isMarketplace() ? 0 : 1;
appliedType = normalizedFacts.getCloudProviderType();
prodCalc.addCloudProvider(
normalizedFacts.getCloudProviderType(), appliedCores, appliedSockets, 1);
}
// Accumulate for physical systems.
else if (!normalizedFacts.isVirtual()) {
appliedSockets = normalizedFacts.isMarketplace() ? 0 : appliedSockets;
appliedType = HardwareMeasurementType.PHYSICAL;
prodCalc.addPhysical(appliedCores, appliedSockets, 1);
}
// Any other system is considered virtual
else {
if (normalizedFacts.isMarketplace()) {
appliedSockets = 0;
}
appliedType = HardwareMeasurementType.VIRTUAL;
prodCalc.addToTotal(appliedCores, appliedSockets, 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Optional<HostTallyBucket> collect(

// Cloud provider hosts only account for a single socket.
if (normalizedFacts.getCloudProviderType() != null) {
appliedSockets = 1;
appliedSockets = normalizedFacts.isMarketplace() ? 0 : 1;
prodCalc.addCloudProvider(
normalizedFacts.getCloudProviderType(), appliedCores, appliedSockets, 1);
return Optional.of(
Expand All @@ -61,7 +61,7 @@ public Optional<HostTallyBucket> collect(
// If the hypervisor is unknown for a guest, we consider it as having a
// unique hypervisor instance contributing to the hypervisor counts.
// Since the guest is unmapped, we only contribute a single socket.
appliedSockets = 1;
appliedSockets = normalizedFacts.isMarketplace() ? 0 : 1;
prodCalc.addHypervisor(appliedCores, appliedSockets, 1);
return Optional.of(
createBucket(
Expand All @@ -70,6 +70,9 @@ public Optional<HostTallyBucket> collect(
// Accumulate for physical systems.
else if (!normalizedFacts.isVirtual()) {
// Physical system so increment the physical system counts.
if (normalizedFacts.isMarketplace()) {
appliedSockets = 0;
}
prodCalc.addPhysical(appliedCores, appliedSockets, 1);
return Optional.of(
createBucket(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ private void normalizeMarketplace(NormalizedFacts normalizedFacts, InventoryHost
return;
}

normalizedFacts.setMarketplace(hostFacts.isMarketplace());
if (normalizedFacts.getCores() != 0) {
normalizedFacts.setCores(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class NormalizedFacts {
private boolean isVirtual;
private boolean isHypervisor;
private boolean isHypervisorUnknown;
private boolean isMarketplace;
private HostHardwareType hardwareType;
private HardwareMeasurementType cloudProviderType;

Expand Down
Loading

0 comments on commit 82df71e

Please sign in to comment.