forked from Ericsson/ecchronos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduction of Rest Module (Ericsson#784)
* Introduction of Rest Module * Fix Wrong Java Docs
- Loading branch information
1 parent
59713af
commit c2ca685
Showing
30 changed files
with
2,765 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.../java/com/ericsson/bss/cassandra/ecchronos/core/impl/metrics/RepairStatsProviderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2024 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.core.impl.metrics; | ||
|
||
import com.datastax.oss.driver.api.core.metadata.Node; | ||
import com.ericsson.bss.cassandra.ecchronos.connection.DistributedNativeConnectionProvider; | ||
import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairStatsProvider; | ||
import com.ericsson.bss.cassandra.ecchronos.core.repair.types.RepairStats; | ||
import com.ericsson.bss.cassandra.ecchronos.core.state.VnodeRepairState; | ||
import com.ericsson.bss.cassandra.ecchronos.core.state.VnodeRepairStateFactory; | ||
import com.ericsson.bss.cassandra.ecchronos.core.state.VnodeRepairStateUtils; | ||
import com.ericsson.bss.cassandra.ecchronos.core.state.VnodeRepairStates; | ||
import com.ericsson.bss.cassandra.ecchronos.core.table.TableReference; | ||
import java.util.Collection; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
public class RepairStatsProviderImpl implements RepairStatsProvider | ||
{ | ||
private final DistributedNativeConnectionProvider myNativeConnectionProvider; | ||
private final VnodeRepairStateFactory myVnodeRepairStateFactory; | ||
|
||
public RepairStatsProviderImpl( | ||
final DistributedNativeConnectionProvider nativeConnectionProvider, | ||
final VnodeRepairStateFactory vnodeRepairStateFactory) | ||
{ | ||
myVnodeRepairStateFactory = vnodeRepairStateFactory; | ||
myNativeConnectionProvider = nativeConnectionProvider; | ||
} | ||
|
||
@Override | ||
public final RepairStats getRepairStats( | ||
final UUID nodeID, | ||
final TableReference tableReference, | ||
final long since, | ||
final long to) | ||
{ | ||
Node node = myNativeConnectionProvider.getNodes().get(nodeID); | ||
VnodeRepairStates vnodeRepairStates; | ||
vnodeRepairStates = myVnodeRepairStateFactory.calculateClusterWideState(node, tableReference, to, since); | ||
Collection<VnodeRepairState> states = vnodeRepairStates.getVnodeRepairStates(); | ||
Collection<VnodeRepairState> repairedStates = states.stream() | ||
.filter(s -> isRepaired(s, since, to)) | ||
.collect(Collectors.toList()); | ||
double repairedRatio = states.isEmpty() ? 0 : (double) repairedStates.size() / states.size(); | ||
return new RepairStats(tableReference.getKeyspace(), tableReference.getTable(), repairedRatio, | ||
VnodeRepairStateUtils.getRepairTime(repairedStates)); | ||
} | ||
|
||
private boolean isRepaired(final VnodeRepairState state, final long since, final long to) | ||
{ | ||
return state.getStartedAt() >= since && state.getFinishedAt() <= to; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/RepairStatsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2024 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.core.repair; | ||
|
||
import com.ericsson.bss.cassandra.ecchronos.core.repair.types.RepairStats; | ||
import com.ericsson.bss.cassandra.ecchronos.core.table.TableReference; | ||
import java.util.UUID; | ||
|
||
public interface RepairStatsProvider | ||
{ | ||
RepairStats getRepairStats(UUID nodeID, TableReference tableReference, long since, long to); | ||
} |
131 changes: 131 additions & 0 deletions
131
.../src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/types/OnDemandRepair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright 2024 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.core.repair.types; | ||
|
||
import com.ericsson.bss.cassandra.ecchronos.core.repair.scheduler.OnDemandRepairJobView; | ||
import com.ericsson.bss.cassandra.ecchronos.utils.enums.repair.RepairType; | ||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
import jakarta.validation.constraints.Max; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.NotBlank; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
|
||
/** | ||
* A representation of an on demand repair. | ||
* | ||
* Primarily used to have a type to convert to JSON. | ||
*/ | ||
@SuppressWarnings("VisibilityModifier") | ||
public class OnDemandRepair | ||
{ | ||
@NotBlank | ||
public UUID id; | ||
@NotBlank | ||
public UUID hostId; | ||
@NotBlank | ||
public String keyspace; | ||
@NotBlank | ||
public String table; | ||
@NotBlank | ||
public OnDemandRepairJobView.Status status; | ||
@NotBlank | ||
@Min(0) | ||
@Max(1) | ||
public double repairedRatio; | ||
@NotBlank | ||
@Min(-1) | ||
public long completedAt; | ||
@NotBlank | ||
public RepairType repairType; | ||
|
||
public OnDemandRepair() | ||
{ | ||
} | ||
|
||
@VisibleForTesting | ||
public OnDemandRepair(final UUID theId, | ||
final UUID theHostId, | ||
final String theKeyspace, | ||
final String theTable, | ||
final OnDemandRepairJobView.Status theStatus, | ||
final double theRepairedRatio, | ||
final long wasCompletedAt, | ||
final RepairType theRepairType) | ||
{ | ||
this.id = theId; | ||
this.hostId = theHostId; | ||
this.keyspace = theKeyspace; | ||
this.table = theTable; | ||
this.status = theStatus; | ||
this.repairedRatio = theRepairedRatio; | ||
this.completedAt = wasCompletedAt; | ||
this.repairType = theRepairType; | ||
} | ||
|
||
|
||
public OnDemandRepair(final OnDemandRepairJobView repairJobView) | ||
{ | ||
this.id = repairJobView.getId(); | ||
this.hostId = repairJobView.getHostId(); | ||
this.keyspace = repairJobView.getTableReference().getKeyspace(); | ||
this.table = repairJobView.getTableReference().getTable(); | ||
this.status = repairJobView.getStatus(); | ||
this.repairedRatio = repairJobView.getProgress(); | ||
this.completedAt = repairJobView.getCompletionTime(); | ||
this.repairType = repairJobView.getRepairType(); | ||
} | ||
|
||
/** | ||
* Equality. | ||
* | ||
* @param o The object to compare to. | ||
* @return boolean | ||
*/ | ||
@Override | ||
public boolean equals(final Object o) | ||
{ | ||
if (this == o) | ||
{ | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) | ||
{ | ||
return false; | ||
} | ||
OnDemandRepair that = (OnDemandRepair) o; | ||
return id.equals(that.id) | ||
&& hostId.equals(that.hostId) | ||
&& keyspace.equals(that.keyspace) | ||
&& table.equals(that.table) | ||
&& status == that.status | ||
&& Double.compare(that.repairedRatio, repairedRatio) == 0 | ||
&& completedAt == that.completedAt | ||
&& repairType.equals(that.repairType); | ||
} | ||
|
||
/** | ||
* Hash code representation. | ||
* | ||
* @return int | ||
*/ | ||
@Override | ||
public int hashCode() | ||
{ | ||
return Objects.hash(id, hostId, keyspace, table, repairedRatio, status, completedAt, repairType); | ||
} | ||
} |
Oops, something went wrong.