From aa131525babb5079de50c5b99e24f2dd9b45a4ad Mon Sep 17 00:00:00 2001 From: ahuang Date: Tue, 16 Jul 2013 02:41:33 -0700 Subject: [PATCH] Added missing files --- .../cloudstack/context/ServerContexts.java | 66 +++++++++++++++++++ utils/src/com/cloud/utils/UuidUtils.java | 23 +++++++ .../cloud/utils/exception/ErrorContext.java | 28 ++++++++ 3 files changed, 117 insertions(+) create mode 100644 engine/components-api/src/org/apache/cloudstack/context/ServerContexts.java create mode 100644 utils/src/com/cloud/utils/UuidUtils.java create mode 100644 utils/src/com/cloud/utils/exception/ErrorContext.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 00000000000..006ba2bd139 --- /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); + } +} diff --git a/utils/src/com/cloud/utils/UuidUtils.java b/utils/src/com/cloud/utils/UuidUtils.java new file mode 100644 index 00000000000..7831beaa753 --- /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('-')); + } +} 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 00000000000..7680a88f830 --- /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, String>> getEntitiesInError(); +}