-
Notifications
You must be signed in to change notification settings - Fork 979
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into origin/master/013_unused_deps
- Loading branch information
Showing
53 changed files
with
2,099 additions
and
929 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
126 changes: 126 additions & 0 deletions
126
agents-common/src/main/java/org/apache/ranger/plugin/model/RangerServerHealth.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,126 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.ranger.plugin.model; | ||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import javax.xml.bind.annotation.XmlAccessType; | ||
import javax.xml.bind.annotation.XmlAccessorType; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY) | ||
@JsonIgnoreProperties(ignoreUnknown=true) | ||
@XmlRootElement | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
@JsonInclude(Include.NON_EMPTY) | ||
public class RangerServerHealth { | ||
public enum RangerServerStatus { | ||
UNKNOWN, INITIALIZING, INITIALIZATION_FAILURE, UP, DOWN | ||
} | ||
|
||
private final RangerServerStatus status; | ||
private final Map<String, Object> details; | ||
|
||
private RangerServerHealth(Builder builder) { | ||
this.status = builder.status; | ||
this.details = Collections.unmodifiableMap(builder.details); | ||
} | ||
|
||
public RangerServerStatus getStatus() { | ||
return this.status; | ||
} | ||
|
||
public Map<String, Object> getDetails() { | ||
return this.details; | ||
} | ||
|
||
public static Builder unknown() { | ||
return status(RangerServerStatus.UNKNOWN); | ||
} | ||
|
||
public static Builder up() { | ||
return status(RangerServerStatus.UP); | ||
} | ||
|
||
public static Builder down() { | ||
return status(RangerServerStatus.DOWN); | ||
} | ||
|
||
public static Builder status(RangerServerStatus status) { | ||
return new Builder(status); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} else if (!(o instanceof RangerServerHealth)) { | ||
return false; | ||
} | ||
|
||
RangerServerHealth health = (RangerServerHealth) o; | ||
|
||
return Objects.equals(status, health.status) && Objects.equals(details, health.details); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(status, details); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getStatus() + " " + getDetails(); | ||
} | ||
|
||
public static class Builder { | ||
private RangerServerStatus status; | ||
private final Map<String, Object> details; | ||
|
||
public Builder() { | ||
this.status = RangerServerStatus.UNKNOWN; | ||
this.details = new LinkedHashMap<>(); | ||
} | ||
|
||
public Builder(RangerServerStatus status) { | ||
this.status = status; | ||
this.details = new LinkedHashMap<>(); | ||
} | ||
|
||
public Builder(RangerServerStatus status, Map<String, ?> details) { | ||
this.status = status; | ||
this.details = new LinkedHashMap<>(details); | ||
} | ||
|
||
public Builder withDetail(String key, Object value) { | ||
this.details.put(key, value); | ||
return this; | ||
} | ||
|
||
public RangerServerHealth build() { | ||
return new RangerServerHealth(this); | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
agents-common/src/test/java/org/apache/ranger/plugin/model/TestRangerHealth.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,76 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.ranger.plugin.model; | ||
|
||
import static org.apache.ranger.plugin.model.RangerServerHealth.RangerServerStatus.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class TestRangerHealth { | ||
@Test | ||
public void testRangerStatusUP() { | ||
Map<String, Object> componentsMap = new HashMap<>(); | ||
Map<String, Object> dbMap = new LinkedHashMap<>(); | ||
dbMap.put("status", UP); | ||
Map<String, Object> dbDetailsMap = new LinkedHashMap<>(); | ||
dbDetailsMap.put("database","Oracle 21.3c"); | ||
dbDetailsMap.put("validationQuery","SELECT banner from v$version where rownum<2"); | ||
dbMap.put("details",dbDetailsMap); | ||
componentsMap.put("db",dbMap); | ||
Map<String, Object> auditProviderMap = new LinkedHashMap<>(); | ||
auditProviderMap.put("status", UP); | ||
Map<String, Object> auditProviderDetailsMap = new LinkedHashMap<>(); | ||
auditProviderDetailsMap.put("provider","Elastic Search"); | ||
auditProviderDetailsMap.put("providerHealthCheckEndpoint","http://localhost:9200/_cluster/health?pretty"); | ||
auditProviderDetailsMap.put("details", auditProviderDetailsMap); | ||
componentsMap.put("auditProvider",auditProviderMap); | ||
RangerServerHealth rangerHealth = RangerServerHealth.up().withDetail("components", componentsMap).build(); | ||
Assert.assertEquals("RangerHealth.up()", UP, rangerHealth.getStatus()); | ||
Assert.assertEquals("RangerHealth.getDetails()", 1, rangerHealth.getDetails().size()); | ||
Assert.assertEquals("RangerHealth.getDetails('component')", 2, ((Map<?, ?>) rangerHealth.getDetails().get("components")).size()); | ||
} | ||
|
||
@Test | ||
public void testRangerStatusDOWN() { | ||
Map<String, Object> componentsMap = new HashMap<>(); | ||
Map<String, Object> dbMap = new LinkedHashMap<>(); | ||
dbMap.put("status", DOWN); | ||
Map<String, Object> dbDetailsMap = new LinkedHashMap<>(); | ||
dbDetailsMap.put("database","Oracle 21.3c"); | ||
dbDetailsMap.put("validationQuery","SELECT banner from v$version where rownum<2"); | ||
dbMap.put("details",dbDetailsMap); | ||
componentsMap.put("db",dbMap); | ||
Map<String, Object> auditProviderMap = new LinkedHashMap<>(); | ||
auditProviderMap.put("status", DOWN); | ||
Map<String, Object> auditProviderDetailsMap = new LinkedHashMap<>(); | ||
auditProviderDetailsMap.put("provider","Elastic Search"); | ||
auditProviderDetailsMap.put("providerHealthCheckEndpoint","http://localhost:9200/_cluster/health?pretty"); | ||
auditProviderDetailsMap.put("details", auditProviderDetailsMap); | ||
componentsMap.put("auditProvider",auditProviderMap); | ||
RangerServerHealth rangerHealth = RangerServerHealth.down().withDetail("components", componentsMap).build(); | ||
Assert.assertEquals("RangerHealth.down()", DOWN, rangerHealth.getStatus()); | ||
Assert.assertEquals("RangerHealth.getDetails()", 1, rangerHealth.getDetails().size()); | ||
Assert.assertEquals("RangerHealth.getDetails('component')", 2, ((Map<?, ?>) rangerHealth.getDetails().get("components")).size()); | ||
} | ||
} |
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
Oops, something went wrong.