Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
866 mhunt 1
package com.erggroup.buildtool.ripple;
2
 
3
import org.apache.log4j.Logger;
4
 
5
import com.erggroup.buildtool.smtp.Smtpsend;
6
 
7
import java.sql.SQLException;
8
import java.util.Iterator;
9
import java.util.Vector;
10
 
11
/**entity class holding build exclusion data
12
 */
13
public class BuildExclusion
14
{
15
  /**Logger
16
   * @attribute
17
   */
18
  private static final Logger mLogger = Logger.getLogger(BuildExclusion.class);
19
 
20
  /**identifier
21
   * @attribute
22
   */
23
  private int mId;
24
 
25
  /**root identifier
26
   * @attribute
27
   */
28
  private int mRootId;
29
 
30
  /**root cause
31
   * @attribute
32
   */
33
  private String mRootCause;
34
 
35
  /**in terms of the mChangeType Package field,
36
   * when true indicates the package has not changed, its dependencies potentially have
37
   * in terms of the mRippleField Package field,
38
   * when true indicates the build number will be incremented
39
   * @attribute
40
   */
41
  private boolean mProcessed = false;
42
 
43
  /**constructor
44
   */
45
  public BuildExclusion(int identifier, int rootIdentifier, String rootCause)
46
  {
47
    mLogger.debug("BuildExclusion");
48
    mId = identifier;
868 mhunt 49
    mRootId = dealWithNullRootPvId(identifier, rootIdentifier);
866 mhunt 50
    mRootCause = rootCause;
51
  }
52
 
53
  /**sets mProcessed true
54
   */
55
  void process()
56
  {
57
    mLogger.debug("process " + mId);
58
    mProcessed = true;
59
  }
60
 
61
  /**accessor
62
   */
63
  boolean isProcessed()
64
  {
65
    mLogger.debug("isProcessed " + mId);
66
    mLogger.info("isProcessed returned " + mProcessed);
67
    return mProcessed;
68
  }
69
 
70
  /**return true if all attributes match
71
   */
72
  boolean compare( int identifier, int rootIdentifier, String rootCause)
73
  {
74
    mLogger.debug("compare " + mId + ", " + identifier + ", " + rootIdentifier + ", " + rootCause);
75
    boolean retVal = false;
868 mhunt 76
    rootIdentifier = dealWithNullRootPvId(identifier, rootIdentifier);
866 mhunt 77
 
78
    if ( mRootCause == null )
79
    {
80
      if ( mId == identifier && mRootId == rootIdentifier && rootCause == null )
81
      {
82
        retVal = true;
83
      }
84
    }
85
    else
86
    {
87
      if ( mId == identifier && mRootId == rootIdentifier && mRootCause.compareTo(rootCause) == 0 )
88
      {
89
        retVal = true;
90
      }
91
    }
92
 
868 mhunt 93
    mLogger.info("compare returned " + retVal);
866 mhunt 94
    return retVal;
95
  }
96
 
97
  /**return true if mId attribute matches
98
   */
99
  boolean compare( int identifier )
100
  {
101
    mLogger.debug("compare " + mId + ", " + identifier);
102
    boolean retVal = false;
103
 
104
    if ( mId == identifier )
105
    {
106
      retVal = true;
107
    }
108
 
109
    mLogger.info("compare returned " + retVal);
110
    return retVal;
111
  }
112
 
113
  /**runs exclude from build
114
   */
115
  void excludeFromBuild( ReleaseManager rm, int rtag_id ) throws SQLException, Exception
116
  {
117
    mLogger.debug("excludeFromBuild " + mId);
118
    Integer id = mId;
119
    Integer rootId = mRootId;
120
    Integer r = rtag_id;
121
    // a null version and log file is passed to oracle
122
    // the planned version is only needed to remove a planned version from the planned version table
123
    // the ripple engine does not get this far ie it excludes pvs before claiming a version
124
    if ( rootId == -1 )
125
    {
126
      rm.excludeFromBuild(id.toString(), null, r.toString(), null, mRootCause, null);
127
    }
128
    else
129
    {
130
      rm.excludeFromBuild(id.toString(), null, r.toString(), rootId.toString(), mRootCause, null);
131
      }
132
  }
133
 
134
  /**runs exclude from build
135
   */
136
  void includeToBuild( ReleaseManager rm, int rtag_id ) throws SQLException, Exception
137
  {
138
    mLogger.debug("includeToBuild " + mId);
139
    Integer id = mId;
140
    Integer r = rtag_id;
141
    // a null version and log file is passed to oracle
142
    // the planned version is only needed to remove a planned version from the planned version table
143
    // the ripple engine does not get this far ie it excludes pvs before claiming a version
144
    rm.includeToBuild(id.toString(), r.toString());
145
  }
146
 
147
  /**
148
   * return true if the root_pv_id is null (-1) or the it points to a pv_id in the collection
149
   */
150
  boolean isRelevant(Vector<BuildExclusion> buildExclusionCollection)
151
  {
152
    mLogger.debug("isRelevant " + mId);
153
    boolean retVal = false;
154
 
155
    if ( mRootId == -1 )
156
    {
157
      retVal = true;
158
    }
159
    else
160
    {
161
      for (Iterator<BuildExclusion> it = buildExclusionCollection.iterator(); it.hasNext(); )
162
      {
163
        BuildExclusion buildExclusion = it.next();
164
 
165
        if ( buildExclusion.isRelevant( mRootId ) )
166
        {
167
          retVal = true;
168
          break;
169
        }
170
      }
171
    }
172
 
173
    mLogger.info("isRelevant " + mId + " returned " + retVal);
174
    return retVal;
175
  }
176
 
177
  /**
178
   * return true if id matches mId
179
   */
180
    private boolean isRelevant(int id)
181
    {
182
      mLogger.debug("isRelevant " + mId + ", " + id);
183
      boolean retVal = false;
184
 
185
      if ( mId == id )
186
      {
187
        retVal = true;
188
      }
189
 
190
      mLogger.info("isRelevant " + mId +  ", " + id + " returned " + retVal);
191
      return retVal;
192
    }
193
 
194
  /**
195
    * user friendly
196
    * does not trigger a storm of emails because a low level package has a build issue
197
    * limit the emails to the low level package
198
    * i.e. only send email if the build exclusion has a null root pv id
199
    * and a non null root cause
200
   */
201
    public void email(Vector<Package>packageCollection, String mailServer, String mailSender, String release)
202
    {
203
      mLogger.debug("email " + mId);
204
      if ( mRootId == -1 && mRootCause != null )
205
      {
206
        // this is a direct build failure with a ripple engine induced root cause
207
        // send email
208
        Package pkg = null;
209
 
210
        for (Iterator<Package> it = packageCollection.iterator(); it.hasNext(); )
211
        {
212
          Package p = it.next();
213
 
214
          if ( compare(p.mId) )
215
          {
216
            pkg = p;
217
            break;
218
          }
219
        }
220
 
221
        if ( pkg != null )
222
        {
223
          // has the pkg any owners
224
          String owners = pkg.emailInfoNonAntTask();
225
 
226
          if ( owners != null )
227
          {
228
            String body =
229
            "Release: " + release + "<p>" +
230
            "Package: " + pkg.mName + "<p>" + 
231
            mRootCause;
232
 
233
            try
234
            {
235
              Smtpsend.send(
236
              mailServer, // mailServer
237
              mailSender, // source
238
              owners, // target
239
              null, // cc
240
              null, // bcc
241
              "BUILD FAILURE on package " + pkg.mName, // subject
242
              body, // body
243
              null // attachment
244
              );
245
            }
246
            catch( Exception e )
247
            {
248
            }
249
          }
250
        }
251
      }
868 mhunt 252
    }
253
 
254
    /**
255
     * hides how a root_pv_id is treated
256
     * only use root_pv_id if not equal to the pv_id
257
     * this is to drive a direct build exclusion in the release manager
258
    */
259
    private int dealWithNullRootPvId( int pvId, int rootPvId )
260
    {
261
      int retVal = rootPvId;
866 mhunt 262
 
868 mhunt 263
      if ( pvId == rootPvId )
264
      {
265
        // force a null root_pv_id in the database
266
        retVal = -1;
267
      }
268
 
269
      return retVal;
866 mhunt 270
    }
271
}