Github user sedukull commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/625#discussion_r35627322
  
    --- Diff: server/src/org/apache/cloudstack/report/UsageReporter.java ---
    @@ -0,0 +1,487 @@
    +// 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.report;
    +
    +import java.util.concurrent.Executors;
    +import java.util.concurrent.ScheduledExecutorService;
    +import java.util.concurrent.TimeUnit;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.HashMap;
    +import java.text.DateFormat;
    +import java.text.SimpleDateFormat;
    +import java.sql.Connection;
    +import java.sql.PreparedStatement;
    +import java.sql.ResultSet;
    +import java.sql.SQLException;
    +import java.net.URL;
    +import java.net.SocketTimeoutException;
    +import java.net.MalformedURLException;
    +import java.net.ProtocolException;
    +import java.net.UnknownHostException;
    +import java.io.OutputStreamWriter;
    +import java.io.IOException;
    +
    +import javax.inject.Inject;
    +import javax.net.ssl.HttpsURLConnection;
    +
    +import org.apache.log4j.Logger;
    +import org.springframework.stereotype.Component;
    +
    +import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
    +import org.apache.cloudstack.managed.context.ManagedContextRunnable;
    +
    +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
    +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
    +
    +import org.apache.commons.codec.digest.DigestUtils;
    +
    +import com.cloud.host.HostVO;
    +import com.cloud.host.dao.HostDao;
    +import com.cloud.dc.ClusterVO;
    +import com.cloud.dc.dao.ClusterDao;
    +import com.cloud.dc.DataCenterVO;
    +import com.cloud.dc.dao.DataCenterDao;
    +import com.cloud.vm.UserVmVO;
    +import com.cloud.vm.dao.UserVmDao;
    +import com.cloud.vm.VMInstanceVO;
    +import com.cloud.vm.dao.VMInstanceDao;
    +import com.cloud.utils.db.SearchCriteria;
    +import com.cloud.utils.NumbersUtil;
    +import com.cloud.utils.component.ManagerBase;
    +import com.cloud.utils.component.ComponentMethodInterceptable;
    +import com.cloud.utils.concurrency.NamedThreadFactory;
    +import com.cloud.utils.db.DB;
    +import com.cloud.utils.db.TransactionLegacy;
    +import com.cloud.upgrade.dao.VersionDao;
    +import com.cloud.upgrade.dao.VersionVO;
    +import com.cloud.storage.dao.DiskOfferingDao;
    +import com.cloud.storage.DiskOfferingVO;
    +import com.google.gson.Gson;
    +import com.google.gson.GsonBuilder;
    +import com.google.common.util.concurrent.AtomicLongMap;
    +
    +@Component
    +public class UsageReporter extends ManagerBase implements 
ComponentMethodInterceptable {
    +    public static final Logger s_logger = 
Logger.getLogger(UsageReporter.class.getName());
    +
    +    /* !FIX ME! This should point to a Apache Infra host with SSL! */
    +    private String reportHost = "https://call-home.cloudstack.org/report";;
    +
    +    private String uniqueID = null;
    +
    +    private static UsageReporter s_instance = null;
    +
    +    private ScheduledExecutorService _executor = null;
    +
    +    @Inject
    +    private ConfigurationDao _configDao;
    +    @Inject
    +    private HostDao _hostDao;
    +    @Inject
    +    private ClusterDao _clusterDao;
    +    @Inject
    +    private PrimaryDataStoreDao _storagePoolDao;
    +    @Inject
    +    private DataCenterDao _dataCenterDao;
    +    @Inject
    +    private UserVmDao _userVmDao;
    +    @Inject
    +    private VMInstanceDao _vmInstance;
    +    @Inject
    +    private VersionDao _versionDao;
    +    @Inject
    +    private DiskOfferingDao _diskOfferingDao;
    +
    +    int usageReportInterval = -1;
    +
    +    public static UsageReporter getInstance() {
    --- End diff --
    
    It seems the purpose is to make only one instance of usagereporter 
available per process and so we added getInstance() method, where user calls 
the getInstance() to get the object reference, in that scenario, 
    1. Make the constructor private. create the  object only when s_instance is 
null. Otherwise, s_instance will be new reference with each new object creation.
    2. It seems we have two overloaded variants of getInstance, not sure which 
one is called and when to use?
    2. Then, if getInstance is called to get an instance of UsageReporter and 
is static, do we want to use lock getinstance code to make it critical section, 
synchronize and avoid race conditions, if multiple threads are calling 
getInstance at the same time, its like two threads using getInstance at the 
sametime first time to create an object.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to