Skip to content

Commit 6dc8ffd

Browse files
committed
Fix Sync of template.properties in Swift
1 parent 6be2cc7 commit 6dc8ffd

File tree

6 files changed

+481
-236
lines changed

6 files changed

+481
-236
lines changed

engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public DataObject create(DataObject obj, DataStore dataStore) {
156156
// template.properties
157157
// there
158158
}
159+
159160
ts.setInstallPath(installPath);
160161
ts.setState(ObjectInDataStoreStateMachine.State.Allocated);
161162
ts = templateDataStoreDao.persist(ts);
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.cloud.test;
20+
21+
import com.google.common.base.Joiner;
22+
import com.google.common.base.Objects;
23+
import com.google.common.collect.ImmutableMap;
24+
import org.apache.log4j.AppenderSkeleton;
25+
import org.apache.log4j.Level;
26+
import org.apache.log4j.Logger;
27+
import org.apache.log4j.spi.LoggingEvent;
28+
import org.springframework.util.Assert;
29+
30+
import java.util.ArrayList;
31+
import java.util.HashMap;
32+
import java.util.HashSet;
33+
import java.util.List;
34+
import java.util.Map;
35+
import java.util.Set;
36+
import java.util.regex.Pattern;
37+
38+
import static com.google.common.base.Preconditions.checkArgument;
39+
import static com.google.common.base.Preconditions.checkState;
40+
import static com.google.common.base.Strings.isNullOrEmpty;
41+
import static java.lang.String.format;
42+
import static org.apache.log4j.Level.ALL;
43+
import static org.apache.log4j.Level.DEBUG;
44+
import static org.apache.log4j.Level.ERROR;
45+
import static org.apache.log4j.Level.FATAL;
46+
import static org.apache.log4j.Level.INFO;
47+
import static org.apache.log4j.Level.OFF;
48+
49+
/**
50+
*
51+
* Tracks one or more patterns to determine whether or not they have been
52+
* logged. It uses a streaming approach to determine whether or not a message
53+
* has a occurred to prevent unnecessary memory consumption. Instances of this
54+
* of this class are created using the {@link TestAppenderBuilder}.
55+
*
56+
* To use this class, register a one or more expected patterns by level as part
57+
* of the test setup and retain an reference to the appender instance. After the
58+
* expected logging events have occurred in the test case, call
59+
* {@link TestAppender#assertMessagesLogged()} which will fail the test if any of the
60+
* expected patterns were not logged.
61+
*
62+
*/
63+
public final class TestAppender extends AppenderSkeleton {
64+
private final static String APPENDER_NAME = "test_appender";
65+
private final ImmutableMap<Level, Set<PatternResult>> expectedPatternResults;
66+
private TestAppender(final Map<Level, Set<PatternResult>> expectedPatterns) {
67+
super();
68+
expectedPatternResults = ImmutableMap.copyOf(expectedPatterns);
69+
}
70+
protected void append(LoggingEvent loggingEvent) {
71+
checkArgument(loggingEvent != null, "append requires a non-null loggingEvent");
72+
final Level level = loggingEvent.getLevel();
73+
checkState(expectedPatternResults.containsKey(level), "level " + level + " not supported by append");
74+
for (final PatternResult patternResult : expectedPatternResults.get(level)) {
75+
if (patternResult.getPattern().matcher(loggingEvent.getRenderedMessage()).matches()) {
76+
patternResult.markFound();
77+
}
78+
}
79+
}
80+
81+
public void close() {
82+
// Do nothing ...
83+
}
84+
public boolean requiresLayout() {
85+
return false;
86+
}
87+
public void assertMessagesLogged() {
88+
final List<String> unloggedPatterns = new ArrayList<>();
89+
for (final Map.Entry<Level, Set<PatternResult>> expectedPatternResult : expectedPatternResults.entrySet()) {
90+
for (final PatternResult patternResults : expectedPatternResult.getValue()) {
91+
if (!patternResults.isFound()) {
92+
unloggedPatterns.add(format("%1$s was not logged for level %2$s",
93+
patternResults.getPattern().toString(), expectedPatternResult.getKey()));
94+
}
95+
}
96+
}
97+
if (!unloggedPatterns.isEmpty()) {
98+
//Raise an assert
99+
Assert.isTrue(false, Joiner.on(",").join(unloggedPatterns));
100+
}
101+
}
102+
103+
private static final class PatternResult {
104+
private final Pattern pattern;
105+
private boolean foundFlag = false;
106+
private PatternResult(Pattern pattern) {
107+
super();
108+
this.pattern = pattern;
109+
}
110+
public Pattern getPattern() {
111+
return pattern;
112+
}
113+
public void markFound() {
114+
// This operation is thread-safe because the value will only ever be switched from false to true. Therefore,
115+
// multiple threads mutating the value for a pattern will not corrupt the value ...
116+
foundFlag = true;
117+
}
118+
public boolean isFound() {
119+
return foundFlag;
120+
}
121+
@Override
122+
public boolean equals(Object thatObject) {
123+
if (this == thatObject) {
124+
return true;
125+
}
126+
if (thatObject == null || getClass() != thatObject.getClass()) {
127+
return false;
128+
}
129+
PatternResult thatPatternResult = (PatternResult) thatObject;
130+
return foundFlag == thatPatternResult.foundFlag &&
131+
Objects.equal(pattern, thatPatternResult.pattern);
132+
}
133+
@Override
134+
public int hashCode() {
135+
return Objects.hashCode(pattern, foundFlag);
136+
}
137+
@Override
138+
public String toString() {
139+
return format("Pattern Result [ pattern: %1$s, markFound: %2$s ]", pattern.toString(), foundFlag);
140+
}
141+
}
142+
143+
public static final class TestAppenderBuilder {
144+
private final Map<Level, Set<PatternResult>> expectedPatterns;
145+
public TestAppenderBuilder() {
146+
super();
147+
expectedPatterns = new HashMap<>();
148+
expectedPatterns.put(ALL, new HashSet<PatternResult>());
149+
expectedPatterns.put(DEBUG, new HashSet<PatternResult>());
150+
expectedPatterns.put(ERROR, new HashSet<PatternResult>());
151+
expectedPatterns.put(FATAL, new HashSet<PatternResult>());
152+
expectedPatterns.put(INFO, new HashSet<PatternResult>());
153+
expectedPatterns.put(OFF, new HashSet<PatternResult>());
154+
}
155+
public TestAppenderBuilder addExpectedPattern(final Level level, final String pattern) {
156+
checkArgument(level != null, "addExpectedPattern requires a non-null level");
157+
checkArgument(!isNullOrEmpty(pattern), "addExpectedPattern requires a non-blank pattern");
158+
checkState(expectedPatterns.containsKey(level), "level " + level + " is not supported by " + getClass().getName());
159+
expectedPatterns.get(level).add(new PatternResult(Pattern.compile(pattern)));
160+
return this;
161+
}
162+
public TestAppender build() {
163+
return new TestAppender(expectedPatterns);
164+
}
165+
}
166+
/**
167+
*
168+
* Attaches a {@link TestAppender} to a {@link Logger} and ensures that it is the only
169+
* test appender attached to the logger.
170+
*
171+
* @param logger The logger which will be monitored by the test
172+
* @param testAppender The test appender to attach to {@code logger}
173+
*/
174+
public static void safeAddAppender(Logger logger, TestAppender testAppender) {
175+
logger.removeAppender(APPENDER_NAME);
176+
logger.addAppender(testAppender);
177+
}
178+
}

services/secondary-storage/server/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
<version>4.7.0-SNAPSHOT</version>
2727
<relativePath>../pom.xml</relativePath>
2828
</parent>
29-
<properties>
30-
<skipTests>true</skipTests>
31-
</properties>
3229
<dependencies>
3330
<dependency>
3431
<groupId>log4j</groupId>

0 commit comments

Comments
 (0)