Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/foundation-2018' into release-24…
Browse files Browse the repository at this point in the history
….1.0
  • Loading branch information
Benjamin Reed committed May 23, 2019
2 parents 30ac736 + 4b6d550 commit 5548b33
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 15 deletions.
31 changes: 25 additions & 6 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
### All Contributors

Thanks for taking time to contribute!
* [ ] Have you read and followed our [Contribution Guidelines](https://github.com/OpenNMS/opennms/blob/develop/CONTRIBUTING.md)?
* [ ] Have you [made an issue in the OpenNMS issue tracker](https://issues.opennms.org)?<br>
If so, you should:
1. update the title of this PR to be of the format: `${JIRA-ISSUE-NUMBER}: subject of pull request`
2. update the JIRA link at the bottom of this comment to refer to the real issue number
3. prefix your commit messages with the issue number, if possible
* [ ] Have you made a comment in that issue which points back to this PR?
* [ ] Have you updated the JIRA link at the bottom of this comment to link to your issue?
* [ ] If this is a new or updated feature, is there documentation for the new behavior?
* [ ] If this is new code, are there unit and/or integration tests?

### Pull Request Process

One or more reviewers should be assigned to each PR.

Please read our [Contribution Guidelines](https://github.com/OpenNMS/opennms/blob/develop/CONTRIBUTING.md) and format the title of the pull request in the format of:
If you know that a particular person is subject matter expert in the area your PR affects, feel free to assign one or more reviewers when you create this PR, otherwise reviewers will be assigned for you.

${JIRA-ISSUE-NUMBER}: a-short-subject-title
Once the reviewer(s) accept the PR and the branch passes continuous integration in Bamboo, the PR is eligible for merge.

At that time, if you have commit access (are an OpenNMS Group employee or a member of the Order of the Green Polo) you are welcome to merge the PR.
Otherwise, a reviewer can merge it for you.

Thanks for taking time to contribute!

Please use the [JIRA](https://issues.opennms.org) issue number and create a link in the JIRA issue back to this pull request so we have a quick reference from the issue to the pull request.
### External References

* JIRA: http://issues.opennms.org/browse/${JIRA-ISSUE-NUMBER}
* JIRA (Issue Tracker): http://issues.opennms.org/browse/${JIRA-ISSUE-NUMBER}
* Bamboo (Continuous Integration): https://bamboo.opennms.org/

Our [continuous integration system](http://bamboo.internal.opennms.com:8085) will test and verify your changes.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
target
.classpath
.externalToolBuilders
.factorypath
.project
.settings
.springBeans
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ private static double getOutageTimeInWindow(List<OnmsOutage> outages, Date start

final long windowStart = start.getTime();
final long windowEnd = end.getTime();
final long windowLength = windowEnd - windowStart;
Preconditions.checkArgument(0 <= windowStart && windowStart < windowEnd);

long downtimeInWindow = 0;
Expand All @@ -218,8 +217,7 @@ private static double getOutageTimeInWindow(List<OnmsOutage> outages, Date start
downtimeInWindow += (regainedAt - lostAt);
}

// Bound the downtime by the length of the window
return Math.min(downtimeInWindow, windowLength);
return downtimeInWindow;
}

private int getNumServices(int nodeId, List<String> serviceNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static org.junit.Assert.assertEquals;

import java.util.Date;
import java.util.List;

import org.easymock.EasyMock;
import org.junit.Before;
Expand All @@ -54,7 +55,7 @@
import org.opennms.test.JUnitConfigurationEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Lists;

Expand All @@ -81,9 +82,6 @@ public class AvailabilityServiceIT implements TemporaryDatabaseAware<MockDatabas
@Autowired
private MonitoredServiceDao m_monitoredServiceDao;

@Autowired
private TransactionTemplate m_transactionTemplate;

private MockDatabase m_mockDatabase;

@Override
Expand Down Expand Up @@ -166,7 +164,60 @@ public void canCalculateAvailability() throws Exception {
assertEquals(2, category.getNode().size());
}

// See NMS-10458
@Test
@Transactional
public void verifyAvailabilityIfEverythingIsDown() {
final MockNetwork mockNetwork = new MockNetwork();
mockNetwork.createStandardNetwork();
m_mockDatabase.populate(mockNetwork);

final RTCCategory rtcCat = EasyMock.createNiceMock(RTCCategory.class);
EasyMock.expect(rtcCat.getLabel()).andReturn("TEST").anyTimes();
EasyMock.expect(rtcCat.getNodes()).andReturn(Lists.newArrayList(1, 2, 3)).anyTimes();
EasyMock.replay(rtcCat);

final long now = System.currentTimeMillis();
final long oneDayAgo = now - (1000 * 60 * 60 * 24);

// Create Outage for Node 1
createOutage(mockNetwork.getService(1, "192.168.1.1", "ICMP"), oneDayAgo);

// Create Outages for Node 2
createOutage(mockNetwork.getService(2, "192.168.1.3", "ICMP"), oneDayAgo);
createOutage(mockNetwork.getService(2, "192.168.1.3", "HTTP"), oneDayAgo);

// Calculate Availability for category
final EuiLevel euiLevel = m_availabilityService.getEuiLevel(rtcCat);
assertEquals(1, euiLevel.getCategory().size());

// Verify Category Availability
final Category category = euiLevel.getCategory().get(0);
assertEquals("TEST", category.getCatlabel());
assertEquals(70.0f, category.getCatvalue(), 0.0001);

// Verify Nodes
final List<Node> nodes = category.getNode();
assertEquals(3, nodes.size());
verifyNode(nodes.get(0), 1, 75.0f);
verifyNode(nodes.get(1), 2, 0.0f);
verifyNode(nodes.get(2), 3, 100.0f);
}

private OnmsMonitoredService toMonitoredService(MockService svc) {
return m_monitoredServiceDao.get(svc.getNodeId(), svc.getAddress(), svc.getSvcName());
}

private void createOutage(MockService mockService, long oneDayAgo) {
final OnmsMonitoredService monitoredService = toMonitoredService(mockService);
final OnmsOutage outage = new OnmsOutage();
outage.setMonitoredService(monitoredService);
outage.setIfLostService(new Date(oneDayAgo));
m_outageDao.save(outage);
}

private static void verifyNode(Node node, long nodeId, float availability) {
assertEquals(nodeId, node.getNodeid());
assertEquals(availability, node.getNodevalue(), 0.0001);
}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<version>2.10.4</version>
<configuration>
<maxmemory>2g</maxmemory>
<maxmemory>3g</maxmemory>
<additionalparam>-Xdoclint:none</additionalparam>
<failOnError>false</failOnError>
<tags>
Expand Down

0 comments on commit 5548b33

Please sign in to comment.