Updated Branches: refs/heads/master fa9ca72f3 -> aa131525b
Added missing files Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/aa131525 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/aa131525 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/aa131525 Branch: refs/heads/master Commit: aa131525babb5079de50c5b99e24f2dd9b45a4ad Parents: 11e1e58 Author: ahuang <alex.hu...@citrix.com> Authored: Tue Jul 16 02:41:33 2013 -0700 Committer: ahuang <alex.hu...@citrix.com> Committed: Tue Jul 16 11:24:21 2013 -0700 ---------------------------------------------------------------------- .../cloudstack/context/ServerContexts.java | 66 ++++++++++++++++++++ utils/src/com/cloud/utils/UuidUtils.java | 23 +++++++ .../com/cloud/utils/exception/ErrorContext.java | 28 +++++++++ 3 files changed, 117 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aa131525/engine/components-api/src/org/apache/cloudstack/context/ServerContexts.java ---------------------------------------------------------------------- diff --git a/engine/components-api/src/org/apache/cloudstack/context/ServerContexts.java b/engine/components-api/src/org/apache/cloudstack/context/ServerContexts.java new file mode 100644 index 0000000..006ba2b --- /dev/null +++ b/engine/components-api/src/org/apache/cloudstack/context/ServerContexts.java @@ -0,0 +1,66 @@ +// 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.cloudstack.context; + +import com.cloud.async.AsyncJob; +import com.cloud.utils.db.Transaction; + +/** + * ServerContextInitializer is responsible for properly setting up the + * contexts that all of the CloudStack code expects. This includes + * - CallContext + * - JobContext + * - TransactionContext + */ +public class ServerContexts { + public static void registerUserContext(long userId, long accountId) { + Transaction txn = Transaction.open(Thread.currentThread().getName()); + CallContext context = CallContext.register(userId, accountId); + context.putContextParameter("Transaction", txn); +// AsyncJobExecutionContext.registerPseudoExecutionContext(userId, accountId); + } + + public static void unregisterUserContext() { + CallContext context = CallContext.unregister(); + if (context != null) { +// AsyncJobExecutionContext.unregister(); + Transaction txn = (Transaction)context.getContextParameter("Transaction"); + txn.close(Thread.currentThread().getName()); + } + } + + /** + * Use this method to initialize the internal background threads. + */ + public static void registerSystemContext() { + Transaction txn = Transaction.open(Thread.currentThread().getName()); + CallContext context = CallContext.registerSystemCallContextOnceOnly(); + context.putContextParameter("Transaction", txn); +// AsyncJobExecutionContext.registerPseudoExecutionContext(Account.ACCOUNT_ID_SYSTEM, User.UID_SYSTEM); + } + + public static void unregisterSystemContext() { + CallContext context = CallContext.unregister(); +// AsyncJobExecutionContext.unregister(); + Transaction txn = (Transaction)context.getContextParameter("Transaction"); + txn.close(Thread.currentThread().getName()); + } + + public static void registerJobContext(long userId, long accountId, AsyncJob job) { + CallContext.register(userId, accountId); + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aa131525/utils/src/com/cloud/utils/UuidUtils.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/UuidUtils.java b/utils/src/com/cloud/utils/UuidUtils.java new file mode 100644 index 0000000..7831bea --- /dev/null +++ b/utils/src/com/cloud/utils/UuidUtils.java @@ -0,0 +1,23 @@ +// 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 com.cloud.utils; + +public class UuidUtils { + public final static String first(String uuid) { + return uuid.substring(0, uuid.indexOf('-')); + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aa131525/utils/src/com/cloud/utils/exception/ErrorContext.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/exception/ErrorContext.java b/utils/src/com/cloud/utils/exception/ErrorContext.java new file mode 100644 index 0000000..7680a88 --- /dev/null +++ b/utils/src/com/cloud/utils/exception/ErrorContext.java @@ -0,0 +1,28 @@ +// 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 com.cloud.utils.exception; + +import java.util.List; + +import com.cloud.utils.Pair; + +public interface ErrorContext { + + ErrorContext add(Class<?> entity, String uuid); + + List<Pair<Class<?>, String>> getEntitiesInError(); +}