|
| 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 org.apache.cloudstack.storage.datastore.configurator.kvm; |
| 20 | + |
| 21 | +import javax.inject.Inject; |
| 22 | + |
| 23 | +import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle; |
| 24 | +import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStore; |
| 25 | +import org.apache.cloudstack.storage.datastore.PrimaryDataStore; |
| 26 | +import org.apache.cloudstack.storage.datastore.configurator.PrimaryDataStoreConfigurator; |
| 27 | +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; |
| 28 | +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO; |
| 29 | +import org.apache.cloudstack.storage.datastore.driver.DefaultPrimaryDataStoreDriverImpl; |
| 30 | +import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver; |
| 31 | +import org.apache.cloudstack.storage.datastore.lifecycle.DefaultKvmPrimaryDataStoreLifeCycle; |
| 32 | + |
| 33 | +import com.cloud.hypervisor.Hypervisor.HypervisorType; |
| 34 | +import com.cloud.utils.exception.CloudRuntimeException; |
| 35 | + |
| 36 | +public abstract class AbstractKvmConfigurator implements PrimaryDataStoreConfigurator { |
| 37 | + @Inject |
| 38 | + PrimaryDataStoreDao dataStoreDao; |
| 39 | + @Override |
| 40 | + public HypervisorType getSupportedHypervisor() { |
| 41 | + return HypervisorType.KVM; |
| 42 | + } |
| 43 | + |
| 44 | + protected PrimaryDataStoreLifeCycle getLifeCycle() { |
| 45 | + return new DefaultKvmPrimaryDataStoreLifeCycle(dataStoreDao); |
| 46 | + } |
| 47 | + |
| 48 | + protected PrimaryDataStoreDriver getDriver() { |
| 49 | + return new DefaultPrimaryDataStoreDriverImpl(); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public PrimaryDataStore getDataStore(long dataStoreId) { |
| 54 | + PrimaryDataStoreVO dataStoreVO = dataStoreDao.findById(dataStoreId); |
| 55 | + if (dataStoreVO == null) { |
| 56 | + throw new CloudRuntimeException("Can't find primary data store: " + dataStoreId); |
| 57 | + } |
| 58 | + |
| 59 | + DefaultPrimaryDataStore dataStore = DefaultPrimaryDataStore.createDataStore(dataStoreVO); |
| 60 | + dataStore.setDriver(this.getDriver()); |
| 61 | + dataStore.setLifeCycle(getLifeCycle()); |
| 62 | + return dataStore; |
| 63 | + } |
| 64 | +} |
0 commit comments