Skip to content

Commit

Permalink
Refactor RepairManagement (#520)
Browse files Browse the repository at this point in the history
Closes #501
  • Loading branch information
itskarlsson authored Jul 27, 2023
1 parent 5880e1d commit e370cbc
Show file tree
Hide file tree
Showing 17 changed files with 1,436 additions and 900 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package com.ericsson.bss.cassandra.ecchronos.application.spring;

import com.ericsson.bss.cassandra.ecchronos.rest.MetricsREST;
import com.ericsson.bss.cassandra.ecchronos.rest.OnDemandRepairManagementRESTImpl;
import com.ericsson.bss.cassandra.ecchronos.rest.RepairManagementRESTImpl;
import com.ericsson.bss.cassandra.ecchronos.rest.ScheduleRepairManagementRESTImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
Expand All @@ -24,7 +26,8 @@
import org.springframework.context.annotation.Import;

@SpringBootApplication
@Import(value = {RepairManagementRESTImpl.class, MetricsREST.class})
@Import(value = {RepairManagementRESTImpl.class, ScheduleRepairManagementRESTImpl.class,
OnDemandRepairManagementRESTImpl.class, MetricsREST.class})
public class SpringBooter extends SpringBootServletInitializer
{
private static final Logger LOG = LoggerFactory.getLogger(SpringBooter.class);
Expand Down
8 changes: 4 additions & 4 deletions docs/autogenerated/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ servers:
- url: https://localhost:8080
description: Generated server url
tags:
- name: Repair-Management
description: Management of repairs
- name: Metrics
description: Retrieve metrics about ecChronos
- name: Repair-Management
description: View the status of schedules and repairs as well as run manual repairs
- name: Actuator
description: Monitor and interact
externalDocs:
Expand Down Expand Up @@ -59,9 +59,9 @@ paths:
tags:
- Repair-Management
summary: Run a manual repair.
description: "Run a manual repair, if 'isLocal' is not provided this will trigger\
description: "Run a manual repair, if 'isLocal' is not provided this will run\
\ a cluster-wide repair."
operationId: trigger-repair
operationId: run-repair
parameters:
- name: keyspace
in: query
Expand Down
4 changes: 2 additions & 2 deletions ecchronos-binary/src/pylib/ecchronoslib/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class V2RepairSchedulerRequest(RestRequest):
v2_repair_status_url = REPAIRS
v2_repair_id_status_url = REPAIRS + '/{0}'

v2_repair_trigger_url = REPAIRS
v2_repair_run_url = REPAIRS

repair_info_url = PROTOCOL + 'repairInfo'

Expand Down Expand Up @@ -187,7 +187,7 @@ def list_repairs(self, keyspace=None, table=None, host_id=None):
return result

def post(self, keyspace=None, table=None, local=False):
request_url = V2RepairSchedulerRequest.v2_repair_trigger_url
request_url = V2RepairSchedulerRequest.v2_repair_run_url
if keyspace:
request_url += "?keyspace=" + keyspace
if table:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2023 Telefonaktiebolaget LM Ericsson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ericsson.bss.cassandra.ecchronos.rest.osgi;

import com.ericsson.bss.cassandra.ecchronos.core.repair.OnDemandRepairScheduler;
import com.ericsson.bss.cassandra.ecchronos.core.repair.types.OnDemandRepair;
import com.ericsson.bss.cassandra.ecchronos.core.utils.ReplicatedTableProvider;
import com.ericsson.bss.cassandra.ecchronos.core.utils.TableReferenceFactory;
import com.ericsson.bss.cassandra.ecchronos.rest.OnDemandRepairManagementREST;
import com.ericsson.bss.cassandra.ecchronos.rest.OnDemandRepairManagementRESTImpl;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.springframework.http.ResponseEntity;

import java.util.List;

/**
* OSGi component wrapping {@link OnDemandRepairManagementREST} bound with OSGi services.
*/
@Component
public class RepairManagementOnDemandRESTComponent implements OnDemandRepairManagementREST
{
@Reference (service = OnDemandRepairScheduler.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.STATIC)
private volatile OnDemandRepairScheduler myOnDemandRepairScheduler;

@Reference(service = TableReferenceFactory.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.STATIC)
private volatile TableReferenceFactory myTableReferenceFactory;

@Reference(service = ReplicatedTableProvider.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.STATIC)
private volatile ReplicatedTableProvider myReplicatedTableProvider;

private volatile OnDemandRepairManagementREST myDelegateOnDemandRESTImpl;

@Activate
public final synchronized void activate()
{
myDelegateOnDemandRESTImpl = new OnDemandRepairManagementRESTImpl(myOnDemandRepairScheduler,
myTableReferenceFactory, myReplicatedTableProvider);
}

@Override
public final ResponseEntity<List<OnDemandRepair>> getRepairs(final String keyspace,
final String table,
final String hostId)
{
return myDelegateOnDemandRESTImpl.getRepairs(keyspace, table, hostId);
}

@Override
public final ResponseEntity<List<OnDemandRepair>> getRepairs(final String id, final String hostId)
{
return myDelegateOnDemandRESTImpl.getRepairs(id, hostId);
}

@Override
public final ResponseEntity<List<OnDemandRepair>> runRepair(final String keyspace,
final String table,
final boolean isLocal)
{
return myDelegateOnDemandRESTImpl.runRepair(keyspace, table, isLocal);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
*/
package com.ericsson.bss.cassandra.ecchronos.rest.osgi;

import com.ericsson.bss.cassandra.ecchronos.core.repair.OnDemandRepairScheduler;
import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairScheduler;
import com.ericsson.bss.cassandra.ecchronos.core.repair.types.OnDemandRepair;
import com.ericsson.bss.cassandra.ecchronos.core.repair.types.RepairInfo;
import com.ericsson.bss.cassandra.ecchronos.core.repair.types.Schedule;
import com.ericsson.bss.cassandra.ecchronos.core.utils.RepairStatsProvider;
import com.ericsson.bss.cassandra.ecchronos.core.utils.ReplicatedTableProvider;
import com.ericsson.bss.cassandra.ecchronos.core.utils.TableReferenceFactory;
Expand All @@ -32,24 +28,13 @@
import org.springframework.http.ResponseEntity;

import java.time.Duration;
import java.util.List;

/**
* OSGi component wrapping {@link RepairManagementREST} bound with OSGi services.
*/
@Component
public class RepairManagementRESTComponent implements RepairManagementREST
{
@Reference (service = RepairScheduler.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.STATIC)
private volatile RepairScheduler myRepairScheduler;

@Reference (service = OnDemandRepairScheduler.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.STATIC)
private volatile OnDemandRepairScheduler myOnDemandRepairScheduler;

@Reference(service = TableReferenceFactory.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.STATIC)
Expand All @@ -69,42 +54,8 @@ public class RepairManagementRESTComponent implements RepairManagementREST
@Activate
public final synchronized void activate()
{
myDelegateRESTImpl = new RepairManagementRESTImpl(myRepairScheduler, myOnDemandRepairScheduler,
myTableReferenceFactory, myReplicatedTableProvider, myRepairStatsProvider);
}

@Override
public final ResponseEntity<List<OnDemandRepair>> getRepairs(final String keyspace,
final String table,
final String hostId)
{
return myDelegateRESTImpl.getRepairs(keyspace, table, hostId);
}

@Override
public final ResponseEntity<List<OnDemandRepair>> getRepairs(final String id, final String hostId)
{
return myDelegateRESTImpl.getRepairs(id, hostId);
}

@Override
public final ResponseEntity<List<Schedule>> getSchedules(final String keyspace, final String table)
{
return myDelegateRESTImpl.getSchedules(keyspace, table);
}

@Override
public final ResponseEntity<Schedule> getSchedules(final String id, final boolean full)
{
return myDelegateRESTImpl.getSchedules(id, full);
}

@Override
public final ResponseEntity<List<OnDemandRepair>> triggerRepair(final String keyspace,
final String table,
final boolean isLocal)
{
return myDelegateRESTImpl.triggerRepair(keyspace, table, isLocal);
myDelegateRESTImpl = new RepairManagementRESTImpl(myTableReferenceFactory,
myReplicatedTableProvider, myRepairStatsProvider);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2023 Telefonaktiebolaget LM Ericsson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ericsson.bss.cassandra.ecchronos.rest.osgi;

import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairScheduler;
import com.ericsson.bss.cassandra.ecchronos.core.repair.types.Schedule;
import com.ericsson.bss.cassandra.ecchronos.rest.ScheduleRepairManagementREST;
import com.ericsson.bss.cassandra.ecchronos.rest.ScheduleRepairManagementRESTImpl;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.springframework.http.ResponseEntity;

import java.util.List;

/**
* OSGi component wrapping {@link ScheduleRepairManagementREST} bound with OSGi services.
*/
@Component
public class RepairManagementScheduleRESTComponent implements ScheduleRepairManagementREST
{
@Reference (service = RepairScheduler.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.STATIC)
private volatile RepairScheduler myRepairScheduler;

private volatile ScheduleRepairManagementREST myDelegateScheduleRESTImpl;

@Activate
public final synchronized void activate()
{
myDelegateScheduleRESTImpl = new ScheduleRepairManagementRESTImpl(myRepairScheduler);
}

@Override
public final ResponseEntity<List<Schedule>> getSchedules(final String keyspace, final String table)
{
return myDelegateScheduleRESTImpl.getSchedules(keyspace, table);
}

@Override
public final ResponseEntity<Schedule> getSchedules(final String id, final boolean full)
{
return myDelegateScheduleRESTImpl.getSchedules(id, full);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2023 Telefonaktiebolaget LM Ericsson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ericsson.bss.cassandra.ecchronos.rest;

import com.ericsson.bss.cassandra.ecchronos.core.repair.types.OnDemandRepair;
import org.springframework.http.ResponseEntity;

import java.util.List;

/**
* On Demand Repair REST interface.
*
* Whenever the interface is changed it must be reflected in docs.
*/
public interface OnDemandRepairManagementREST
{
/**
* Get a list of on demand repairs. Will fetch all if no keyspace or table is specified.
*
* @param keyspace The keyspace of the table (optional)
* @param table The table to get status of (optional)
* @param hostId The hostId of the on demand repair (optional)
* @return A list of JSON representations of {@link OnDemandRepair}
*/
ResponseEntity<List<OnDemandRepair>> getRepairs(String keyspace, String table, String hostId);
/**
* Get a list of on demand repairs associated with a specific id.
*
* @param id The id of the on demand repair
* @param hostId The hostId of the on demand repair (optional)
* @return A list of JSON representations of {@link OnDemandRepair}
*/
ResponseEntity<List<OnDemandRepair>> getRepairs(String id, String hostId);

/**
* Schedule an on demand repair to be run on a specific table.
*
* @param keyspace The keyspace of the table
* @param table The table
* @param isLocal If repair should be only run for the local node (optional)
* @return A JSON representation of {@link OnDemandRepair}
*/
ResponseEntity<List<OnDemandRepair>> runRepair(String keyspace, String table, boolean isLocal);
}
Loading

0 comments on commit e370cbc

Please sign in to comment.