001/* 002 * (C) Copyright 2017 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Mariana Cedica 018 */ 019package org.nuxeo.ecm.core.storage.status; 020 021import java.util.Map; 022 023import org.nuxeo.ecm.blob.s3.S3BlobProvider; 024import org.nuxeo.ecm.core.blob.BlobManager; 025import org.nuxeo.ecm.core.blob.BlobProvider; 026import org.nuxeo.ecm.core.blob.binary.BinaryManager; 027import org.nuxeo.ecm.core.storage.sql.S3BinaryManager; 028import org.nuxeo.runtime.api.Framework; 029import org.nuxeo.runtime.management.api.Probe; 030import org.nuxeo.runtime.management.api.ProbeStatus; 031 032/** 033 * Probe to check the status of the S3BinaryManager. Returns success if Nuxeo can access the bucket, failure otherwise 034 * 035 * @since 9.3 036 */ 037public class S3BinaryManagerStatusProbe implements Probe { 038 039 @Override 040 public ProbeStatus run() { 041 Map<String, BlobProvider> providers = Framework.getService(BlobManager.class).getBlobProviders(); 042 boolean found = false; 043 for (Map.Entry<String, BlobProvider> en : providers.entrySet()) { 044 String id = en.getKey(); 045 BlobProvider blobProvider = en.getValue(); 046 BinaryManager bm = blobProvider.getBinaryManager(); 047 if (bm instanceof S3BinaryManager) { 048 if (!((S3BinaryManager) bm).canAccessBucket()) { 049 return ProbeStatus.newFailure("S3BinaryManager cannot access the configured bucket: " + id); 050 } 051 found = true; 052 } else if (bm instanceof S3BlobProvider) { 053 if (!((S3BlobProvider) bm).canAccessBucket()) { 054 return ProbeStatus.newFailure("S3BinaryManager cannot access the configured bucket: " + id); 055 } 056 found = true; 057 } 058 } 059 if (found) { 060 return ProbeStatus.newSuccess("S3BinaryManager can access the configured buckets"); 061 } else { 062 return ProbeStatus.newSuccess("No S3BinaryManager bucket configured"); 063 } 064 } 065 066}