Skip to content

Commit aa13152

Browse files
author
ahuang
committed
Added missing files
1 parent 11e1e58 commit aa13152

3 files changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.context;
18+
19+
import com.cloud.async.AsyncJob;
20+
import com.cloud.utils.db.Transaction;
21+
22+
/**
23+
* ServerContextInitializer is responsible for properly setting up the
24+
* contexts that all of the CloudStack code expects. This includes
25+
* - CallContext
26+
* - JobContext
27+
* - TransactionContext
28+
*/
29+
public class ServerContexts {
30+
public static void registerUserContext(long userId, long accountId) {
31+
Transaction txn = Transaction.open(Thread.currentThread().getName());
32+
CallContext context = CallContext.register(userId, accountId);
33+
context.putContextParameter("Transaction", txn);
34+
// AsyncJobExecutionContext.registerPseudoExecutionContext(userId, accountId);
35+
}
36+
37+
public static void unregisterUserContext() {
38+
CallContext context = CallContext.unregister();
39+
if (context != null) {
40+
// AsyncJobExecutionContext.unregister();
41+
Transaction txn = (Transaction)context.getContextParameter("Transaction");
42+
txn.close(Thread.currentThread().getName());
43+
}
44+
}
45+
46+
/**
47+
* Use this method to initialize the internal background threads.
48+
*/
49+
public static void registerSystemContext() {
50+
Transaction txn = Transaction.open(Thread.currentThread().getName());
51+
CallContext context = CallContext.registerSystemCallContextOnceOnly();
52+
context.putContextParameter("Transaction", txn);
53+
// AsyncJobExecutionContext.registerPseudoExecutionContext(Account.ACCOUNT_ID_SYSTEM, User.UID_SYSTEM);
54+
}
55+
56+
public static void unregisterSystemContext() {
57+
CallContext context = CallContext.unregister();
58+
// AsyncJobExecutionContext.unregister();
59+
Transaction txn = (Transaction)context.getContextParameter("Transaction");
60+
txn.close(Thread.currentThread().getName());
61+
}
62+
63+
public static void registerJobContext(long userId, long accountId, AsyncJob job) {
64+
CallContext.register(userId, accountId);
65+
}
66+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.utils;
18+
19+
public class UuidUtils {
20+
public final static String first(String uuid) {
21+
return uuid.substring(0, uuid.indexOf('-'));
22+
}
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.utils.exception;
18+
19+
import java.util.List;
20+
21+
import com.cloud.utils.Pair;
22+
23+
public interface ErrorContext {
24+
25+
ErrorContext add(Class<?> entity, String uuid);
26+
27+
List<Pair<Class<?>, String>> getEntitiesInError();
28+
}

0 commit comments

Comments
 (0)