-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix #3203 usage server broken in 4.11/4.12 #3207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9a3a67a
353251b
4c948e0
7a5649e
a42bc9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,9 @@ After=network.target network-online.target | |
| [Service] | ||
| Type=simple | ||
| EnvironmentFile=/etc/default/cloudstack-usage | ||
| ExecStart=/usr/bin/java $JAVA_OPTS -cp $CLASSPATH $JAVA_CLASS | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put this and this would fix the pid issue:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment: this would need to be fixed for 4.11 as well, let me send a quick fix instead. |
||
| ExecStart=/usr/bin/java $JAVA_DEBUG $JAVA_OPTS -cp $CLASSPATH $JAVA_CLASS | ||
| ExecStartPost=/bin/sh -c "systemctl show -p MainPID cloudstack-usage.service 2>/dev/null | cut -d= -f2 > /var/run/cloudstack-usage.service.pid" | ||
|
|
||
| Restart=always | ||
| RestartSec=10s | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // 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 | ||
| // 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.cloud.usage; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.charset.Charset; | ||
|
|
||
| import org.apache.commons.io.FileUtils; | ||
| import org.apache.commons.lang3.math.NumberUtils; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.InOrder; | ||
| import org.mockito.Mockito; | ||
| import org.powermock.api.mockito.PowerMockito; | ||
| import org.powermock.core.classloader.annotations.PrepareForTest; | ||
| import org.powermock.modules.junit4.PowerMockRunner; | ||
|
|
||
| import com.cloud.utils.exception.CloudRuntimeException; | ||
|
|
||
| @RunWith(PowerMockRunner.class) | ||
| @PrepareForTest({FileUtils.class, UsageManagerImpl.class, NumberUtils.class}) | ||
| public class UsageManagerImplTest { | ||
|
|
||
| private static final String CLOUDSTACK_USAGE_SERVER_SERVICE_PID_FILE = "/var/run/cloudstack-usage.service.pid"; | ||
| private UsageManagerImpl usageManagerImpl = new UsageManagerImpl(); | ||
|
|
||
| @Test | ||
| public void retrieveUsageManagerServicePidTestCompleteExecutionFlow() throws Exception { | ||
| prepareAndVerifyTestRetrieveUsageManagerServicePidTest(true, true, 1, 1234, "1234" + System.getProperty("line.separator")); | ||
| } | ||
|
|
||
| @Test(expected=CloudRuntimeException.class) | ||
| public void retrieveUsageManagerServicePidTestFileDoesNotExist() throws Exception { | ||
| prepareAndVerifyTestRetrieveUsageManagerServicePidTest(false, true, 0, 1234, "1234" + System.getProperty("line.separator")); | ||
| } | ||
|
|
||
| @Test(expected = CloudRuntimeException.class) | ||
| public void retrieveUsageManagerServicePidTestCannotReadFile() throws Exception { | ||
| prepareAndVerifyTestRetrieveUsageManagerServicePidTest(true, false, 1, 1234, "1234" + System.getProperty("line.separator")); | ||
| } | ||
|
|
||
| @Test(expected = CloudRuntimeException.class) | ||
| public void retrieveUsageManagerServicePidTestPidEqualsToZero() throws Exception { | ||
| prepareAndVerifyTestRetrieveUsageManagerServicePidTest(true, true, 1, 0, "abc"); | ||
| } | ||
|
|
||
| private void prepareAndVerifyTestRetrieveUsageManagerServicePidTest(boolean fileExists, boolean canReadFile, int timesCanReadIsExecuted, int expectedPid, | ||
| String readedStringFromFile) | ||
| throws Exception, IOException { | ||
| File usageServicePid = Mockito.mock(File.class); | ||
| PowerMockito.whenNew(File.class).withArguments(CLOUDSTACK_USAGE_SERVER_SERVICE_PID_FILE).thenReturn(usageServicePid); | ||
|
|
||
| Mockito.when(usageServicePid.exists()).thenReturn(fileExists); | ||
| Mockito.when(usageServicePid.canRead()).thenReturn(canReadFile); | ||
|
|
||
| PowerMockito.mockStatic(FileUtils.class); | ||
| Mockito.when(FileUtils.readFileToString(usageServicePid, Charset.defaultCharset())).thenReturn(readedStringFromFile); | ||
|
|
||
| int result = usageManagerImpl.retrieveUsageManagerServicePid(); | ||
|
|
||
| InOrder inOrder = Mockito.inOrder(usageServicePid); | ||
| inOrder.verify(usageServicePid).exists(); | ||
| inOrder.verify(usageServicePid, Mockito.times(timesCanReadIsExecuted)).canRead(); | ||
|
|
||
| Assert.assertEquals(expectedPid, result); | ||
| } | ||
|
|
||
| } |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GabrielBrascher What's the issue, this should work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, re-read the description. Alright keep this change, I'll advise you a simpler fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, this without quotes would work